@@ -133,7 +133,7 @@ func TestParsingSimpleString(t *testing.T) {
133
133
134
134
assert .Equal (t , rootNode .ToSexp (), "(source_file (struct_item name: (type_identifier) body: (field_declaration_list)) (function_item name: (identifier) parameters: (parameters) body: (block)))" )
135
135
136
- structNode := rootNode .Child (0 )
136
+ structNode := nodeMust ( rootNode .Child (0 ) )
137
137
assert .Equal (t , structNode .Kind (), "struct_item" )
138
138
}
139
139
@@ -232,7 +232,7 @@ func TestParsingWithCustomUTF8Input(t *testing.T) {
232
232
assert .Equal (t , root .ToSexp (), "(source_file (function_item (visibility_modifier) name: (identifier) parameters: (parameters) body: (block (integer_literal))))" )
233
233
assert .Equal (t , root .Kind (), "source_file" )
234
234
assert .False (t , root .HasError ())
235
- assert .Equal (t , root .Child (0 ).Kind (), "function_item" )
235
+ assert .Equal (t , nodeMust ( root .Child (0 ) ).Kind (), "function_item" )
236
236
}
237
237
238
238
func TestParsingWithCustomUTF16LEInput (t * testing.T ) {
@@ -266,7 +266,7 @@ func TestParsingWithCustomUTF16LEInput(t *testing.T) {
266
266
assert .Equal (t , root .ToSexp (), "(source_file (function_item (visibility_modifier) name: (identifier) parameters: (parameters) body: (block (integer_literal))))" )
267
267
assert .Equal (t , root .Kind (), "source_file" )
268
268
assert .False (t , root .HasError ())
269
- assert .Equal (t , root .Child (0 ).Kind (), "function_item" )
269
+ assert .Equal (t , nodeMust ( root .Child (0 ) ).Kind (), "function_item" )
270
270
}
271
271
272
272
func TestParsingWithCustomUTF16BEInput (t * testing.T ) {
@@ -311,7 +311,7 @@ func TestParsingWithCustomUTF16BEInput(t *testing.T) {
311
311
assert .Equal (t , root .ToSexp (), "(source_file (function_item (visibility_modifier) name: (identifier) parameters: (parameters) body: (block (integer_literal))))" )
312
312
assert .Equal (t , root .Kind (), "source_file" )
313
313
assert .False (t , root .HasError ())
314
- assert .Equal (t , root .Child (0 ).Kind (), "function_item" )
314
+ assert .Equal (t , nodeMust ( root .Child (0 ) ).Kind (), "function_item" )
315
315
}
316
316
317
317
func TestParsingWithCallbackReturningOwnedStrings (t * testing.T ) {
@@ -717,7 +717,7 @@ func TestParsingWithTimeout(t *testing.T) {
717
717
nil ,
718
718
nil ,
719
719
)
720
- assert .Equal (t , "array" , tree .RootNode ().Child (0 ).Kind ())
720
+ assert .Equal (t , "array" , nodeMust ( tree .RootNode ().Child (0 ) ).Kind ())
721
721
}
722
722
723
723
func TestParsingWithTimeoutAndReset (t * testing.T ) {
@@ -753,7 +753,7 @@ func TestParsingWithTimeoutAndReset(t *testing.T) {
753
753
// it does not see the changes to the beginning of the source code.
754
754
code = []byte ("[null, 1, 2, 3, 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]" )
755
755
tree = parser .ParseWithOptions (callback , nil , nil )
756
- assert .Equal (t , "string" , tree .RootNode ().NamedChild (0 ).NamedChild (0 ).Kind ())
756
+ assert .Equal (t , "string" , nodeMust ( nodeMust ( tree .RootNode ().NamedChild (0 )) .NamedChild (0 ) ).Kind ())
757
757
758
758
code = []byte ("[\" ok\" , 1, 2, 3, 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]" )
759
759
tree = parser .ParseWithOptions (
@@ -770,7 +770,7 @@ func TestParsingWithTimeoutAndReset(t *testing.T) {
770
770
parser .Reset ()
771
771
code = []byte ("[null, 1, 2, 3, 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]" )
772
772
tree = parser .ParseWithOptions (callback , nil , nil )
773
- assert .Equal (t , "null" , tree .RootNode ().NamedChild (0 ).NamedChild (0 ).Kind ())
773
+ assert .Equal (t , "null" , nodeMust ( nodeMust ( tree .RootNode ().NamedChild (0 )) .NamedChild (0 ) ).Kind ())
774
774
}
775
775
776
776
func TestParsingWithTimeoutAndImplicitReset (t * testing.T ) {
@@ -805,7 +805,7 @@ func TestParsingWithTimeoutAndImplicitReset(t *testing.T) {
805
805
parser .SetLanguage (getLanguage ("json" ))
806
806
code = []byte ("[null, 1, 2, 3, 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]" )
807
807
tree = parser .ParseWithOptions (callback , nil , nil )
808
- assert .Equal (t , "null" , tree .RootNode ().NamedChild (0 ).NamedChild (0 ).Kind ())
808
+ assert .Equal (t , "null" , nodeMust ( nodeMust ( tree .RootNode ().NamedChild (0 )) .NamedChild (0 ) ).Kind ())
809
809
}
810
810
811
811
func TestParsingWithTimeoutAndNoCompletion (t * testing.T ) {
@@ -951,7 +951,7 @@ func TestParsingWithOneIncludedRange(t *testing.T) {
951
951
defer parser .Close ()
952
952
parser .SetLanguage (getLanguage ("html" ))
953
953
htmlTree := parser .Parse ([]byte (sourceCode ), nil )
954
- scriptContentNode := htmlTree .RootNode ().Child (1 ).Child (1 )
954
+ scriptContentNode := nodeMust ( nodeMust ( htmlTree .RootNode ().Child (1 )) .Child (1 ) )
955
955
assert .Equal (t , "raw_text" , scriptContentNode .Kind ())
956
956
957
957
assert .Equal (t , []Range {
@@ -985,16 +985,16 @@ func TestParsingWithMultipleIncludedRanges(t *testing.T) {
985
985
defer parser .Close ()
986
986
parser .SetLanguage (getLanguage ("javascript" ))
987
987
jsTree := parser .Parse ([]byte (sourceCode ), nil )
988
- templateStringNode := jsTree .RootNode ().DescendantForByteRange (
988
+ templateStringNode := nodeMust ( jsTree .RootNode ().DescendantForByteRange (
989
989
uint (strings .Index (sourceCode , "`<" )),
990
990
uint (strings .Index (sourceCode , ">`" )),
991
- )
991
+ ))
992
992
assert .Equal (t , "template_string" , templateStringNode .Kind ())
993
993
994
- openQuoteNode := templateStringNode .Child (0 )
995
- interpolationNode1 := templateStringNode .Child (2 )
996
- interpolationNode2 := templateStringNode .Child (4 )
997
- closeQuoteNode := templateStringNode .Child (6 )
994
+ openQuoteNode := nodeMust ( templateStringNode .Child (0 ) )
995
+ interpolationNode1 := nodeMust ( templateStringNode .Child (2 ) )
996
+ interpolationNode2 := nodeMust ( templateStringNode .Child (4 ) )
997
+ closeQuoteNode := nodeMust ( templateStringNode .Child (6 ) )
998
998
999
999
parser .SetLanguage (getLanguage ("html" ))
1000
1000
htmlRanges := []Range {
@@ -1027,11 +1027,11 @@ func TestParsingWithMultipleIncludedRanges(t *testing.T) {
1027
1027
)
1028
1028
assert .Equal (t , htmlRanges , htmlTree .IncludedRanges ())
1029
1029
1030
- divElementNode := htmlTree .RootNode ().Child (0 )
1031
- helloTextNode := divElementNode .Child (1 )
1032
- bElementNode := divElementNode .Child (2 )
1033
- bStartTagNode := bElementNode .Child (0 )
1034
- bEndTagNode := bElementNode .Child (1 )
1030
+ divElementNode := nodeMust ( htmlTree .RootNode ().Child (0 ) )
1031
+ helloTextNode := nodeMust ( divElementNode .Child (1 ) )
1032
+ bElementNode := nodeMust ( divElementNode .Child (2 ) )
1033
+ bStartTagNode := nodeMust ( bElementNode .Child (0 ) )
1034
+ bEndTagNode := nodeMust ( bElementNode .Child (1 ) )
1035
1035
1036
1036
assert .Equal (t , "text" , helloTextNode .Kind ())
1037
1037
assert .Equal (t , uint (strings .Index (sourceCode , "Hello" )), helloTextNode .StartByte ())
@@ -1164,8 +1164,8 @@ func TestParsingWithExternalScannerThatUsesIncludedRangeBoundaries(t *testing.T)
1164
1164
tree := parser .Parse ([]byte (sourceCode ), nil )
1165
1165
defer tree .Close ()
1166
1166
root := tree .RootNode ()
1167
- statement1 := root .Child (0 )
1168
- statement2 := root .Child (1 )
1167
+ statement1 := nodeMust ( root .Child (0 ) )
1168
+ statement2 := nodeMust ( root .Child (1 ) )
1169
1169
1170
1170
assert .Equal (
1171
1171
t ,
0 commit comments