-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfragment_test.go
72 lines (65 loc) · 1.15 KB
/
fragment_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
package prosemirror
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFragment_findIndex(t *testing.T) {
s := Must(NewSchema(SchemaSpec{
Nodes: map[NodeTypeName]NodeSpec{
"doc": {
Content: "block+",
},
"paragraph": {
Content: "inline*",
Group: "block",
},
"text": {
Group: "inline",
},
},
TopNode: "doc",
}))
newP := func(text string) Node {
return s.Node("paragraph", nil, NewFragment(s.Text(text)))
}
tests := []struct {
name string
f Fragment
pos int
index int
offset int
}{
{
name: "empty fragment",
f: NewFragment(),
pos: 0,
index: 0,
offset: 0,
},
{
name: "text node",
f: NewFragment(s.Text("Hello World!")),
pos: 5,
index: 0,
offset: 0,
},
{
name: "basic doc",
f: NewFragment(
newP("Crazy?"),
newP("I was crazy once."),
newP("They put me in a room."),
),
pos: 14,
index: 1,
offset: 8,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
index, offset := tt.f.findIndex(tt.pos)
assert.Equal(t, tt.index, index)
assert.Equal(t, tt.offset, offset)
})
}
}