github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/util/bytes/bytes_test.go (about) 1 package bytes 2 3 import ( 4 "fmt" 5 6 . "github.com/insionng/yougam/libraries/pingcap/check" 7 ) 8 9 var _ = Suite(&testBytesHelperSuites{}) 10 11 type testBytesHelperSuites struct{} 12 13 func (s *testBytesHelperSuites) TestBytesClone(c *C) { 14 b := []byte("hello world") 15 shadowB := b 16 newB := CloneBytes(b) 17 c.Assert(b, DeepEquals, newB) 18 // Ugly hacks.Go doesn't allow compare two slice (except nil). 19 // For example: b == newB <-- it's invalid. 20 // In this test, we must ensure CloneBytes method returns a new slice with 21 // the same value, so we need to check the new slice's address. 22 c.Assert(fmt.Sprintf("%p", b) != fmt.Sprintf("%p", newB), IsTrue) 23 // But the addresses are the same when it's a shadow copy. 24 c.Assert(fmt.Sprintf("%p", b), Equals, fmt.Sprintf("%p", shadowB)) 25 }