github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/encoding/base64/std.base64_test.go (about) 1 package base64 2 3 import ( 4 "bytes" 5 "strings" 6 "testing" 7 ) 8 9 func TestStdToByte(t *testing.T) { 10 input := []byte("你好") 11 except := "5L2g5aW9" 12 actual := EncodeBytes(input) 13 if !strings.EqualFold(except, actual) { 14 t.Errorf("test fail actual:%s, except:%s", actual, except) 15 } 16 17 actualByte, err := DecodeBytes(actual) 18 if err != nil { 19 t.Errorf("test fail err : %v", err) 20 } 21 if !bytes.EqualFold(actualByte, input) { 22 t.Error("test fail") 23 } 24 25 errInput := "!@#!" 26 _, err = DecodeBytes(errInput) 27 if err == nil { 28 t.Error("测试错误") 29 return 30 } 31 } 32 33 func TestStdToString(t *testing.T) { 34 input := "你好" 35 except := "5L2g5aW9" 36 actual := Encode(input) 37 if !strings.EqualFold(except, actual) { 38 t.Errorf("test fail actual:%s, except:%s", actual, except) 39 } 40 41 actual, err := Decode(actual) 42 if err != nil { 43 t.Errorf("test fail err : %v", err) 44 } 45 if !strings.EqualFold(actual, input) { 46 t.Error("test fail") 47 } 48 49 errInput := "!@#!" 50 _, err = Decode(errInput) 51 if err == nil { 52 t.Error("测试错误") 53 return 54 } 55 }