github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/encoding/unicode/unicode_test.go (about) 1 package unicode 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestEncode(t *testing.T) { 9 input := "你好" 10 except := "\\u4f60\\u597d" 11 actual := Encode(input) 12 if !strings.EqualFold(except, actual) { 13 t.Errorf("Encode fail %s to %s", except, actual) 14 } 15 16 input = "hello world" 17 except = "hello world" 18 actual = Encode(input) 19 if !strings.EqualFold(except, actual) { 20 t.Errorf("Encode fail %s to %s", except, actual) 21 } 22 23 input = "!@#!" 24 except = "!@#!" 25 actual = Encode(input) 26 if !strings.EqualFold(except, actual) { 27 t.Errorf("Encode fail %s to %s", except, actual) 28 } 29 } 30 31 func TestDecode(t *testing.T) { 32 input := "\\u4f60\\u597d" 33 except := "你好" 34 actual := Decode(input) 35 if !strings.EqualFold(except, actual) { 36 t.Errorf("Decode fail %s to %s", except, actual) 37 } 38 39 input = "\\u0068\\u0065\\u006c\\u006c\\u006f\\u0020\u0077\\u006f\\u0072\\u006c\\u0064" 40 except = "hello world" 41 actual = Decode(input) 42 if !strings.EqualFold(except, actual) { 43 t.Errorf("Decode fail %s to %s", except, actual) 44 } 45 46 input = "!@#!" 47 except = "!@#!" 48 actual = Decode(input) 49 if !strings.EqualFold(except, actual) { 50 t.Errorf("Decode fail %s to %s", except, actual) 51 } 52 }