|
|
- package modhex
-
- import (
- "encoding/hex"
- "strings"
- "testing"
- )
-
- type test struct {
- hex string
- modhex string
- }
-
- func TestEncodeHexDecodeHex(t *testing.T) {
- var tests = []test{
- {
- modhex: "dteffuje",
- hex: "2d344e83",
- },
-
- {
- modhex: "DTEFFUJE",
- hex: "2d344e83",
- },
-
- {
- modhex: "dTeFfUjE",
- hex: "2d344e83",
- },
-
- {
- modhex: "hknhfjbrjnlnldnhcujvddbikngjrtgh",
- hex: "69b6481c8baba2b60e8f22179b58cd56",
- },
-
- {
- modhex: "urtubjtnuihvntcreeeecvbregfjibtn",
- hex: "ecde18dbe76fbd0c33330f1c354871db",
- },
- }
-
- for _, tc := range tests {
- src, _ := hex.DecodeString(tc.hex)
- modhex := EncodeToString(src)
-
- if modhex != strings.ToLower(modhex) {
- t.Errorf("Encode Incorrect: Actual: %s; Expected: %s\n", modhex, tc.modhex)
- }
-
- hexBytes, err := DecodeString(tc.modhex)
- if err != nil {
- t.Error(err)
- }
-
- hexStr := hex.EncodeToString(hexBytes)
- if hexStr != tc.hex {
- t.Errorf("Decode Incorrect: Actual: %s; Expected: %s\n", hexStr, tc.hex)
- }
- }
- }
|