File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff 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+
4453const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4554const (
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
83102func BenchmarkBytesConvBytesToStrRaw (b * testing.B ) {
You can’t perform that action at this time.
0 commit comments