-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_test.go
83 lines (70 loc) · 1.59 KB
/
node_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
package prosemirror_test
import (
"reflect"
"testing"
"github.com/go-json-experiment/json"
"github.com/karitham/prosemirror"
b "github.com/karitham/prosemirror/builder"
"github.com/karitham/prosemirror/schema"
)
func TestNodeCalcSize(t *testing.T) {
b := b.New(prosemirror.Must(prosemirror.NewSchema(schema.DefaultSpec)))
n := b.Doc(
b.PText("Crazy?"),
b.PText("I was crazy once."),
b.PText("They put me in a room."),
b.PText("A rubber room."),
b.PText("A rubber room with rats."),
b.PText("Rubber rats."),
b.PText("I hate rats."),
)
if n.Content.Size != 121 {
t.Errorf("NodeSize() = %v, want %v", n.Content.Size, 121)
}
}
func TestNodeIndexing(t *testing.T) {
b := b.New(prosemirror.Must(prosemirror.NewSchema(schema.DefaultSpec)))
type test struct {
name string
got prosemirror.Node
want int
}
tests := []test{{
name: "default doc",
want: 121,
got: b.Doc(
b.PText("Crazy?"),
b.PText("I was crazy once."),
b.PText("They put me in a room."),
b.PText("A rubber room."),
b.PText("A rubber room with rats."),
b.PText("Rubber rats."),
b.PText("I hate rats."),
),
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if !reflect.DeepEqual(tt.got.Content.Size, tt.want) {
t.Errorf("DocSize() = %v, want %v", tt.got.Content.Size, tt.want)
}
})
}
}
func must[T any](t T, err error) T {
if err != nil {
panic(err)
}
return t
}
func fromJSON[T any](s string) T {
var t T
err := json.Unmarshal([]byte(s), &t)
if err != nil {
panic(err)
}
return t
}
func toJSON(v any) string {
b, _ := json.Marshal(v)
return string(b)
}