github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/byte/utils_test.go (about) 1 // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package byteutils_test 4 5 import ( 6 "bytes" 7 byteutils "github.com/TeaOSLab/EdgeNode/internal/utils/byte" 8 "github.com/iwind/TeaGo/assert" 9 "testing" 10 ) 11 12 func TestCopy(t *testing.T) { 13 var a = assert.NewAssertion(t) 14 15 var prefix []byte 16 prefix = append(prefix, 1, 2, 3) 17 t.Log(prefix, byteutils.Copy(prefix)) 18 a.IsTrue(bytes.Equal(byteutils.Copy(prefix), []byte{1, 2, 3})) 19 } 20 21 func TestAppend(t *testing.T) { 22 var as = assert.NewAssertion(t) 23 24 var prefix []byte 25 prefix = append(prefix, 1, 2, 3) 26 27 // [1 2 3 4 5 6] [1 2 3 7] 28 var a = byteutils.Append(prefix, 4, 5, 6) 29 var b = byteutils.Append(prefix, 7) 30 t.Log(a, b) 31 32 as.IsTrue(bytes.Equal(a, []byte{1, 2, 3, 4, 5, 6})) 33 as.IsTrue(bytes.Equal(b, []byte{1, 2, 3, 7})) 34 } 35 36 func TestConcat(t *testing.T) { 37 var a = assert.NewAssertion(t) 38 39 var prefix []byte 40 prefix = append(prefix, 1, 2, 3) 41 42 var b = byteutils.Concat(prefix, []byte{4, 5, 6}, []byte{7}) 43 t.Log(b) 44 45 a.IsTrue(bytes.Equal(b, []byte{1, 2, 3, 4, 5, 6, 7})) 46 } 47 48 func TestAppend_Raw(t *testing.T) { 49 var prefix []byte 50 prefix = append(prefix, 1, 2, 3) 51 52 // [1 2 3 7 5 6] [1 2 3 7] 53 var a = append(prefix, 4, 5, 6) 54 var b = append(prefix, 7) 55 t.Log(a, b) 56 }