-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookahead_iter_test.go
107 lines (83 loc) · 2.04 KB
/
lookahead_iter_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package sitter
import (
"context"
"testing"
)
func TestNewLookaheadIterator(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLookaheadIteratorNext()")
}
func TestLookaheadIteratorDelete(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLookaheadIteratorNext()")
}
func TestLookaheadIteratorResetState(t *testing.T) {
t.Parallel()
t.Skip("TODO")
}
func TestLookaheadIteratorReset(t *testing.T) {
t.Parallel()
t.Skip("TODO")
}
func TestLookaheadIteratorLanguage(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLookaheadIteratorNext()")
}
func TestLookaheadIteratorNext(t *testing.T) {
t.Parallel()
source := "1 + "
input := []byte(source)
root, err := Parse(context.Background(), input, gr)
if err != nil {
t.Fatal("Expected no error, got", err)
}
t.Log(root)
c := NewTreeCursor(root)
ok1 := c.GoToFirstChild()
ok2 := c.GoToFirstChild()
ok3 := c.GoToNextSibling()
if !ok1 || !ok2 || !ok3 {
t.Fatal("Node navigation failed")
}
iter := NewLookaheadIterator(gr, c.CurrentNode().ParseState())
if iter == nil {
t.Fatal("Could not get iter")
}
defer iter.Delete()
gr2 := iter.Language()
if gr2.ptr != gr.ptr {
t.Fatal("The language differs")
}
testCases := []struct {
expSym uint16
expName string
}{
{maxUint16, "ERROR"},
{5, "comment"},
{0, "end"},
{2, ")"},
{3, "+"},
}
for i, tc := range testCases {
if actSym := iter.CurrentSymbol(); uint16(actSym) != tc.expSym {
t.Fatalf("Expected symbol %d, got %d", tc.expSym, actSym)
}
if actName := iter.CurrentSymbolName(); actName != tc.expName {
t.Fatalf("Expected symbol name %q, got %q", tc.expName, actName)
}
if i == len(testCases)-1 {
return
}
if !iter.Next() {
t.Fatalf("Iterator could not advance from %v", tc)
}
}
}
func TestLookaheadIteratorCurrentSymbol(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLookaheadIteratorNext()")
}
func TestLookaheadIteratorCurrentSymbolName(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLookaheadIteratorNext()")
}