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