github.com/XiaoMi/Gaea@v1.2.5/util/hack/hack_test.go (about) 1 // Copyright 2016 The kingshard Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package hack 16 17 import ( 18 "bytes" 19 "testing" 20 ) 21 22 func TestString(t *testing.T) { 23 b := []byte("hello world") 24 a := String(b) 25 26 if a != "hello world" { 27 t.Fatal(a) 28 } 29 30 b[0] = 'a' 31 32 if a != "aello world" { 33 t.Fatal(a) 34 } 35 36 b = append(b, "abc"...) 37 if a != "aello world" { 38 t.Fatal(a) 39 } 40 } 41 42 func TestByte(t *testing.T) { 43 a := "hello world" 44 45 b := Slice(a) 46 47 if !bytes.Equal(b, []byte("hello world")) { 48 t.Fatal(string(b)) 49 } 50 }