Skip to content

Commit 2422b94

Browse files
committed
internal/bytesconv: add tests for empty and nil cases
1 parent 771dcc6 commit 2422b94

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/bytesconv/bytesconv_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ func TestBytesToString(t *testing.T) {
4141
}
4242
}
4343

44+
func TestBytesToStringEmpty(t *testing.T) {
45+
if got := BytesToString([]byte{}); got != "" {
46+
t.Fatalf("BytesToString([]byte{}) = %q; want empty string", got)
47+
}
48+
if got := BytesToString(nil); got != "" {
49+
t.Fatalf("BytesToString(nil) = %q; want empty string", got)
50+
}
51+
}
52+
4453
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4554
const (
4655
letterIdxBits = 6 // 6 bits to represent a letter index
@@ -78,6 +87,16 @@ func TestStringToBytes(t *testing.T) {
7887
}
7988
}
8089

90+
func TestStringToBytesEmpty(t *testing.T) {
91+
b := StringToBytes("")
92+
if len(b) != 0 {
93+
t.Fatalf(`StringToBytes("") length = %d; want 0`, len(b))
94+
}
95+
if !bytes.Equal(b, []byte("")) {
96+
t.Fatalf(`StringToBytes("") = %v; want []byte("")`, b)
97+
}
98+
}
99+
81100
// go test -v -run=none -bench=^BenchmarkBytesConv -benchmem=true
82101

83102
func BenchmarkBytesConvBytesToStrRaw(b *testing.B) {

0 commit comments

Comments
 (0)