-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathELM_test.go
88 lines (79 loc) · 2.29 KB
/
ELM_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package rdx
import (
"testing"
"github.com/drpcorg/chotki/protocol"
"github.com/stretchr/testify/assert"
)
func TestMap(t *testing.T) {
var correct = []byte{
0x6D, 0x15,
0x36, 0x03, 0x00, 0xaf, 0x00, 0x0b, 0x0b,
0x73, 0x04, 0x30, 0x4b, 0x65, 0x79,
0x73, 0x06, 0x30, 0x56, 0x61, 0x6c, 0x75, 0x65,
}
id := IDFromString("b0b-af0-3")
env2 := protocol.Record('M',
protocol.TinyRecord('I', id.ZipBytes()),
protocol.Record('S', protocol.TinyRecord('T', ZipIntUint64Pair(0, 0)), []byte("Key")),
protocol.Record('S', protocol.TinyRecord('T', ZipIntUint64Pair(0, 0)), []byte("Value")),
)
assert.Equal(t, correct, env2)
}
func TestMapConversions(t *testing.T) {
tt := MapTT{
"nil": "false",
"true": "false",
"false": "false",
}
tlv := MtlvTT(tt)
tt2 := MnativeTT(tlv)
assert.Equal(t, tt, tt2)
diff := MapTT{
"''": "false",
"true": "true",
}
difftlv := MtlvTT(diff)
stamped := Restamp(difftlv, Time{1, 1})
// todo changes
mergedtlv := Mmerge(protocol.Records{tlv, stamped})
mergedtt := MnativeTT(mergedtlv)
assert.Equal(t, mergedtt["''"], "false")
assert.Equal(t, mergedtt["true"], "true")
}
func TestEmerge(t *testing.T) {
tlv1 := Eparse("{1, 2, \"four\"}")
assert.Equal(t, "{1,2,\"four\"}", Estring(tlv1))
tlv2 := Eparse("{3, \"four\", 5}")
tlv12 := Emerge(protocol.Records{tlv1, tlv2})
str12 := Estring(tlv12)
assert.Equal(t, "{1,2,3,\"four\",5}", str12)
del := Itlve(-1, 0, 1)
tlv12d := Emerge(protocol.Records{tlv1, tlv2, del})
str12d := Estring(tlv12d)
assert.Equal(t, "{2,3,\"four\",5}", str12d)
}
func TestMmerge(t *testing.T) {
tlv1 := Mparse("{1: 2, 5:6, 3: 4}")
assert.Equal(t, "{1:2,3:4,5:6}", Mstring(tlv1))
tlv2 := Mparse("{ 7:8, 3:4, 5:6}")
tlv12 := Mmerge(protocol.Records{tlv1, tlv2})
str12 := Mstring(tlv12)
assert.Equal(t, "{1:2,3:4,5:6,7:8}", str12)
del := protocol.Concat(
Itlve(-1, 0, 5),
Itlve(-1, 0, 6), // todo T
)
tlv12d := Mmerge(protocol.Records{tlv1, tlv2, del})
str12d := Mstring(tlv12d)
assert.Equal(t, "{1:2,3:4,7:8}", str12d)
}
func TestLmerge(t *testing.T) {
tlv1 := Lparse("[1, 2, 3, 5]")
assert.Equal(t, "[1,2,3,5]", Lstring(tlv1))
patch1 := protocol.Record('B',
protocol.TinyRecord('T', ZipIntUint64Pair(3, 0)),
Itlve(5, 0, 4),
)
tlv2 := Lmerge(protocol.Records{tlv1, patch1})
assert.Equal(t, "[1,2,3,4,5]", Lstring(tlv2))
}