gitee.com/gricks/utils@v1.0.8/strings_test.go (about) 1 package utils 2 3 import ( 4 "testing" 5 6 . "github.com/smartystreets/goconvey/convey" 7 ) 8 9 func Test_Hex2Byte_Byte2Hex(t *testing.T) { 10 Convey("Hex2Byte", t, func() { 11 s := "ff15" 12 b := Hex2Byte(s) 13 So(s, ShouldEqual, Byte2Hex(b)) 14 }) 15 } 16 17 func Test_IgnoreBOM(t *testing.T) { 18 Convey("IgnoreBOM", t, func() { 19 b1 := []byte{0xEF, 0xBB, 0xBF, 'a', 'b', 'c'} 20 b2 := []byte{'a', 'b', 'c'} 21 b3 := []byte{0xEF, 0xBF, 'a', 'b', 'c'} 22 b4 := []byte{} 23 var b5 []byte 24 So(IgnoreBOM(b1), ShouldResemble, []byte{'a', 'b', 'c'}) 25 So(IgnoreBOM(b2), ShouldResemble, []byte{'a', 'b', 'c'}) 26 So(IgnoreBOM(b3), ShouldResemble, []byte{0xEF, 0xBF, 'a', 'b', 'c'}) 27 So(IgnoreBOM(b4), ShouldResemble, []byte{}) 28 So(IgnoreBOM(b5), ShouldBeNil) 29 }) 30 }