87 lines
1.8 KiB
Go
87 lines
1.8 KiB
Go
|
package jsonpack
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestAstEncode(t *testing.T) {
|
||
|
a := "1+2|3^4%5"
|
||
|
b := "1%2B2%7C3%5E4%255"
|
||
|
|
||
|
b1 := astEncode(a)
|
||
|
|
||
|
if b == b1 {
|
||
|
t.Logf("输入=>%s, 输出=>%s", a, b)
|
||
|
} else {
|
||
|
t.Fatalf("输入=>%s, 预计输出=>%s, 实际输出=>%s", a, b, b1)
|
||
|
}
|
||
|
t.Log("done")
|
||
|
}
|
||
|
|
||
|
func TestAstDecode(t *testing.T) {
|
||
|
a := "1%2B2%7C3%5E4%255"
|
||
|
b := "1+2|3^4%5"
|
||
|
|
||
|
b1 := astDecode(a)
|
||
|
|
||
|
if b == b1 {
|
||
|
t.Logf("输入=>%s, 输出=>%s", a, b)
|
||
|
} else {
|
||
|
t.Fatalf("输入=>%s, 预计输出=>%s, 实际输出=>%s", a, b, b1)
|
||
|
}
|
||
|
t.Log("done")
|
||
|
}
|
||
|
|
||
|
func TestAstBase10to36(t *testing.T) {
|
||
|
a := 65036
|
||
|
b := "1e6k"
|
||
|
b1 := astBase10to36(a)
|
||
|
|
||
|
if b == b1 {
|
||
|
t.Logf("输入(10)=>%d, 输出(36)=>%s", a, b)
|
||
|
} else {
|
||
|
t.Fatalf("输入(10)=>%d, 输出(36)=>%s", a, b1)
|
||
|
}
|
||
|
t.Log("done")
|
||
|
}
|
||
|
|
||
|
func TestAstBase36to10(t *testing.T) {
|
||
|
a := "1e6k"
|
||
|
b := 65036
|
||
|
b1 := astBase36to10(a)
|
||
|
|
||
|
if b == b1 {
|
||
|
t.Logf("输入(36)=>%s, 输出(10)=>%d", a, b)
|
||
|
} else {
|
||
|
t.Fatalf("输入(36)=>%s, 输出(10)=>%d", a, b1)
|
||
|
}
|
||
|
t.Log("done")
|
||
|
}
|
||
|
|
||
|
func TestPack(t *testing.T) {
|
||
|
a := map[string]string{"France": "Paris", "Italy": "Rome", "Japan": "Tokyo", "India": "New delhi"}
|
||
|
a1 := []any{"France2", "France1", "1", nil, 123, 123.2222, -15555, -1.2, false, true, a}
|
||
|
|
||
|
b := "France2|France1|1|France|Paris|Italy|Rome|Japan|Tokyo|India|New+delhi^3f|-c03^123.2222|-1.2^@0|1|2|b|d|c|e|-2|-1|$3|4|5|6|7|8|9|a]]"
|
||
|
|
||
|
b1, _ := Pack(a1)
|
||
|
|
||
|
if b == b1 {
|
||
|
t.Logf("\n 输入=>%s \n 输出=>%s", a1, b)
|
||
|
} else {
|
||
|
t.Fatalf("\n 输入=>%s \n 预计输出=>%s \n 实际输出=>%s", a1, b, b1)
|
||
|
}
|
||
|
|
||
|
t.Log("done")
|
||
|
}
|
||
|
|
||
|
func TestUnpack(t *testing.T) {
|
||
|
a := "Fran\"ce2|Franc什么e1|1|France|Pa:ris|Italy|Rome|Japan|Tokyo|India|New+delhi^3f|-c03^123.2222|-1.2^@0|1|2|b|d|c|e|-2|-1|$3|4|5|6|7|8|9|a]]"
|
||
|
|
||
|
b, _ := Unpack(a)
|
||
|
|
||
|
// fmt.Sprintf("类型: %T, 内容: %+v", b, b)
|
||
|
t.Logf(b)
|
||
|
}
|