mirror of
https://github.com/gin-gonic/gin.git
synced 2025-12-03 13:39:34 +08:00
test(bytesconv): add tests for empty/nil cases (#4454)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
af6e8b70b8
commit
583db590ec
@ -41,6 +41,15 @@ func TestBytesToString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBytesToStringEmpty(t *testing.T) {
|
||||||
|
if got := BytesToString([]byte{}); got != "" {
|
||||||
|
t.Fatalf("BytesToString([]byte{}) = %q; want empty string", got)
|
||||||
|
}
|
||||||
|
if got := BytesToString(nil); got != "" {
|
||||||
|
t.Fatalf("BytesToString(nil) = %q; want empty string", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
const (
|
const (
|
||||||
letterIdxBits = 6 // 6 bits to represent a letter index
|
letterIdxBits = 6 // 6 bits to represent a letter index
|
||||||
@ -78,6 +87,16 @@ func TestStringToBytes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStringToBytesEmpty(t *testing.T) {
|
||||||
|
b := StringToBytes("")
|
||||||
|
if len(b) != 0 {
|
||||||
|
t.Fatalf(`StringToBytes("") length = %d; want 0`, len(b))
|
||||||
|
}
|
||||||
|
if !bytes.Equal(b, []byte("")) {
|
||||||
|
t.Fatalf(`StringToBytes("") = %v; want []byte("")`, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// go test -v -run=none -bench=^BenchmarkBytesConv -benchmem=true
|
// go test -v -run=none -bench=^BenchmarkBytesConv -benchmem=true
|
||||||
|
|
||||||
func BenchmarkBytesConvBytesToStrRaw(b *testing.B) {
|
func BenchmarkBytesConvBytesToStrRaw(b *testing.B) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user