-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsubcontainers_test.go
More file actions
181 lines (156 loc) · 3.95 KB
/
Copy pathsubcontainers_test.go
File metadata and controls
181 lines (156 loc) · 3.95 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package loro
import "testing"
func TestLoroMap_GetOrCreateLoroChildren(t *testing.T) {
doc := NewLoroDoc()
root := doc.GetMap(AsContainerId("root"))
cm, err := root.GetOrCreateLoroMap("m")
if err != nil {
t.Fatalf("GetOrCreateLoroMap: %v", err)
}
if !cm.IsAttached() {
t.Fatal("child map should be attached")
}
cl, err := root.GetOrCreateLoroList("l")
if err != nil {
t.Fatalf("GetOrCreateLoroList: %v", err)
}
if !cl.IsAttached() {
t.Fatal("child list should be attached")
}
cml, err := root.GetOrCreateLoroMovableList("ml")
if err != nil {
t.Fatalf("GetOrCreateLoroMovableList: %v", err)
}
if !cml.IsAttached() {
t.Fatal("child movable list should be attached")
}
ct, err := root.GetOrCreateLoroText("t")
if err != nil {
t.Fatalf("GetOrCreateLoroText: %v", err)
}
if !ct.IsAttached() {
t.Fatal("child text should be attached")
}
ctr, err := root.GetOrCreateLoroTree("tr")
if err != nil {
t.Fatalf("GetOrCreateLoroTree: %v", err)
}
if !ctr.IsAttached() {
t.Fatal("child tree should be attached")
}
cc, err := root.GetOrCreateLoroCounter("c")
if err != nil {
t.Fatalf("GetOrCreateLoroCounter: %v", err)
}
if !cc.IsAttached() {
t.Fatal("child counter should be attached")
}
}
func TestLoroMap_GetOrCreateLoroMap_idempotent(t *testing.T) {
doc := NewLoroDoc()
root := doc.GetMap(AsContainerId("root"))
first, err := root.GetOrCreateLoroMap("m")
if err != nil {
t.Fatalf("first GetOrCreateLoroMap: %v", err)
}
must(t, first.InsertAny("k", "v"))
second, err := root.GetOrCreateLoroMap("m")
if err != nil {
t.Fatalf("second GetOrCreateLoroMap: %v", err)
}
if got, ok := second.GetString("k"); !ok || got != "v" {
t.Fatalf("second call should yield the existing child, got (%q, %v)", got, ok)
}
}
func TestLoroList_InsertLoroChildren(t *testing.T) {
doc := NewLoroDoc()
l := doc.GetList(AsContainerId("l"))
cm, err := l.InsertLoroMap(0)
if err != nil {
t.Fatalf("InsertLoroMap: %v", err)
}
if !cm.IsAttached() {
t.Fatal("inserted map should be attached")
}
cl, err := l.InsertLoroList(1)
if err != nil {
t.Fatalf("InsertLoroList: %v", err)
}
if !cl.IsAttached() {
t.Fatal("inserted list should be attached")
}
cml, err := l.InsertLoroMovableList(2)
if err != nil {
t.Fatalf("InsertLoroMovableList: %v", err)
}
if !cml.IsAttached() {
t.Fatal("inserted movable list should be attached")
}
ct, err := l.InsertLoroText(3)
if err != nil {
t.Fatalf("InsertLoroText: %v", err)
}
if !ct.IsAttached() {
t.Fatal("inserted text should be attached")
}
ctr, err := l.InsertLoroTree(4)
if err != nil {
t.Fatalf("InsertLoroTree: %v", err)
}
if !ctr.IsAttached() {
t.Fatal("inserted tree should be attached")
}
cc, err := l.InsertLoroCounter(5)
if err != nil {
t.Fatalf("InsertLoroCounter: %v", err)
}
if !cc.IsAttached() {
t.Fatal("inserted counter should be attached")
}
}
func TestLoroMovableList_InsertLoroChildren(t *testing.T) {
doc := NewLoroDoc()
ml := doc.GetMovableList(AsContainerId("ml"))
cm, err := ml.InsertLoroMap(0)
if err != nil {
t.Fatalf("InsertLoroMap: %v", err)
}
if !cm.IsAttached() {
t.Fatal("inserted map should be attached")
}
cl, err := ml.InsertLoroList(1)
if err != nil {
t.Fatalf("InsertLoroList: %v", err)
}
if !cl.IsAttached() {
t.Fatal("inserted list should be attached")
}
cml, err := ml.InsertLoroMovableList(2)
if err != nil {
t.Fatalf("InsertLoroMovableList: %v", err)
}
if !cml.IsAttached() {
t.Fatal("inserted movable list should be attached")
}
ct, err := ml.InsertLoroText(3)
if err != nil {
t.Fatalf("InsertLoroText: %v", err)
}
if !ct.IsAttached() {
t.Fatal("inserted text should be attached")
}
ctr, err := ml.InsertLoroTree(4)
if err != nil {
t.Fatalf("InsertLoroTree: %v", err)
}
if !ctr.IsAttached() {
t.Fatal("inserted tree should be attached")
}
cc, err := ml.InsertLoroCounter(5)
if err != nil {
t.Fatalf("InsertLoroCounter: %v", err)
}
if !cc.IsAttached() {
t.Fatal("inserted counter should be attached")
}
}