Skip to content
Myr

test(bytesconv): add tests for empty/nil cases (#4454)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Milad · committed by GitHub · parent af6e8b7 · Browse files · 1 file+19 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>

Diff stats

1 file+19 added−0 removed

  • other:+19 added−0 removed

1 file+19 added−0 removed

modified:internal/bytesconv/bytesconv_test.go+19 added
39 unmodified lines
40 }41 }42}4344func 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}5253const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"54const (55 letterIdxBits = 6 // 6 bits to represent a letter index56 letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
29 unmodified lines
86 }87 }88}8990func 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}99100// go test -v -run=none -bench=^BenchmarkBytesConv -benchmem=true101102func BenchmarkBytesConvBytesToStrRaw(b *testing.B) {103 for b.Loop() {
21 unmodified lines