-
Notifications
You must be signed in to change notification settings - Fork 0
/
language_test.go
178 lines (143 loc) · 3.6 KB
/
language_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
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
package sitter
import "testing"
func TestLanguageCopy(t *testing.T) {
t.Parallel()
gr2 := gr.Copy()
if gr.ptr != gr2.ptr {
t.Fatal("The two grammars differ")
}
}
func TestLanguageDelete(t *testing.T) {
t.Parallel()
gr2 := gr.Copy()
gr2.Delete()
// Not sure what else I could test.
// How could I possibly test that C freed the memory?
if gr2.ptr != nil {
t.Fatal("Expected gr2 to be deleted")
}
}
func TestLanguage(t *testing.T) {
t.Parallel()
exp := uint32(9)
if x := gr.SymbolCount(); x != exp {
t.Fatalf("Expected symbol count to be %d, got %d", exp, x)
}
expStr := "Regular"
if x := SymbolTypeRegular.String(); x != expStr {
t.Fatalf("Expected regular symbol type to be %q, got %q", expStr, x)
}
testCases := []struct {
n Symbol
expName string
expType SymbolType
isNamed bool
}{
{0, "end", SymbolTypeAuxiliary, true},
{1, "(", SymbolTypeAnonymous, false},
{2, ")", SymbolTypeAnonymous, false},
{3, "+", SymbolTypeAnonymous, false},
{4, "number", SymbolTypeRegular, true},
{5, "comment", SymbolTypeRegular, true},
{6, "variable", SymbolTypeRegular, true},
{7, "expression", SymbolTypeRegular, true},
{8, "sum", SymbolTypeRegular, true},
{9, "", SymbolTypeAuxiliary, false},
}
for _, tc := range testCases {
t.Run("", func(t *testing.T) {
t.Parallel()
symName := gr.SymbolName(tc.n)
if symName != tc.expName {
t.Fatalf("Expected symbol name %q got %q for %d", tc.expName, symName, tc.n)
}
symID := gr.SymbolID(symName, tc.isNamed)
if symName != "" && symID != tc.n {
t.Fatalf("Expected symbol ID %d got %d for %q", tc.n, symID, symName)
}
symType := gr.SymbolType(tc.n)
if symType != tc.expType {
t.Fatalf("Expected symbol type %d got %d for %d", tc.expType, symType, tc.n)
}
})
}
}
func TestLanguageSymbolCount(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLanguage()")
}
func TestLanguageStateCount(t *testing.T) {
t.Parallel()
exp := uint32(9)
if act := gr.StateCount(); act != exp {
t.Fatalf("Expected state count to be %d, got %d", exp, act)
}
}
func TestLanguageSymbolName(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLanguage()")
}
func TestLanguageSymbolID(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLanguage()")
}
func TestLanguageFieldCount(t *testing.T) {
t.Parallel()
exp := uint32(2)
if act := gr.FieldCount(); act != exp {
t.Fatalf("Expected field count to be %d, got %d", exp, act)
}
}
func TestLanguageFieldName(t *testing.T) {
t.Parallel()
testCases := []struct {
n int
exp string
}{
{0, ""},
{1, "left"},
{2, "right"},
}
for _, tc := range testCases {
t.Run(tc.exp, func(t *testing.T) {
t.Parallel()
if act := gr.FieldName(tc.n); act != tc.exp {
t.Fatalf("Expected %q, got %q for %d", tc.exp, act, tc.n)
}
})
}
}
func TestLanguageFieldID(t *testing.T) {
t.Parallel()
testCases := []struct {
exp FieldID
n string
}{
{0, ""},
{1, "left"},
{2, "right"},
}
for _, tc := range testCases {
t.Run(tc.n, func(t *testing.T) {
t.Parallel()
if act := gr.FieldID(tc.n); act != tc.exp {
t.Fatalf("Expected %d, got %q for %q", tc.exp, act, tc.n)
}
})
}
}
func TestLanguageSymbolType(t *testing.T) {
t.Parallel()
t.Skip("tested implicitly via TestLanguage()")
}
func TestLanguageVersion(t *testing.T) {
t.Parallel()
exp := TREE_SITTER_LANGUAGE_VERSION
if act := gr.Version(); act != exp {
t.Fatalf("Expected %d, got %d", exp, act)
}
}
func TestLanguageNextState(t *testing.T) {
t.Parallel()
t.Skip("won't test: not really the Go code's job to assert the parser parses correctly")
}