7 cmn "github.com/tendermint/tmlibs/common"
10 func TestParse(t *testing.T) {
11 testParse(t, `"foobar"`, `"foobar"`)
12 testParse(t, "0x1234", "0x1234")
13 testParse(t, "0xbeef", "0xBEEF")
14 testParse(t, "xbeef", "xBEEF")
15 testParse(t, "12345", "{i 12345}")
16 testParse(t, "u64:12345", "{u64 12345}")
17 testParse(t, "i64:12345", "{i64 12345}")
18 testParse(t, "i64:-12345", "{i64 -12345}")
19 testParse(t, "[1 u64:2]", "[{i 1},{u64 2}]")
20 testParse(t, "[(1 2) (3 4)]", "[({i 1} {i 2}),({i 3} {i 4})]")
21 testParse(t, "0x1234 1 u64:2 [3 4]", "(0x1234 {i 1} {u64 2} [{i 3},{i 4}])")
22 testParse(t, "[(1 <sig:user1>)(2 <sig:user2>)][3 4]",
23 "([({i 1} <sig:user1>),({i 2} <sig:user2>)] [{i 3},{i 4}])")
26 func testParse(t *testing.T, input string, expected string) {
27 got, err := ParseReader(input, strings.NewReader(input))
32 gotStr := cmn.Fmt("%v", got)
33 if gotStr != expected {
34 t.Error(cmn.Fmt("Expected %v, got %v", expected, gotStr))
38 func TestBytes(t *testing.T) {
39 testBytes(t, `"foobar"`, `0106666F6F626172`)
40 testBytes(t, "0x1234", "01021234")
41 testBytes(t, "0xbeef", "0102BEEF")
42 testBytes(t, "xbeef", "BEEF")
43 testBytes(t, "12345", "023039")
44 testBytes(t, "u64:12345", "0000000000003039")
45 testBytes(t, "i64:12345", "0000000000003039")
46 testBytes(t, "i64:-12345", "FFFFFFFFFFFFCFC7")
47 testBytes(t, "[1 u64:2]", "010201010000000000000002")
48 testBytes(t, "[(1 2) (3 4)]", "01020101010201030104")
49 testBytes(t, "0x1234 1 u64:2 [3 4]", "0102123401010000000000000002010201030104")
50 testBytes(t, "[(1 <sig:user1>)(2 <sig:user2>)][3 4]",
51 "0102010100010200010201030104")
54 func testBytes(t *testing.T, input string, expected string) {
55 got, err := ParseReader(input, strings.NewReader(input))
60 gotBytes, err := got.(Byteful).Bytes()
65 gotHex := cmn.Fmt("%X", gotBytes)
66 if gotHex != expected {
67 t.Error(cmn.Fmt("Expected %v, got %v", expected, gotHex))