github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/encoding/hex/hex_test.go (about)

     1  package hex
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestEncode(t *testing.T) {
     9  	enInput := "www.baidu.com"
    10  	enExcept := "7777772e62616964752e636f6d"
    11  	enActual := Encode([]byte(enInput))
    12  	if !strings.EqualFold(enExcept, enActual) {
    13  		t.Errorf("Encode fail %s to %s", enExcept, enActual)
    14  	}
    15  
    16  	deInput := "7777772e62616964752e636f6d"
    17  	deExcept := "www.baidu.com"
    18  	deActual, err := Decode(deInput)
    19  	if err != nil {
    20  		t.Error("Decode错误")
    21  	}
    22  	if !strings.EqualFold(deExcept, deActual) {
    23  		t.Errorf("Decode fail %s to %s", deExcept, deActual)
    24  	}
    25  
    26  	errInput := "!@#!$"
    27  	_, err = Decode(errInput)
    28  	if err == nil {
    29  		t.Error("测试失败")
    30  	}
    31  }