@@ -133,7 +133,7 @@ func TestParsingSimpleString(t *testing.T) {
133133
134134 assert .Equal (t , rootNode .ToSexp (), "(source_file (struct_item name: (type_identifier) body: (field_declaration_list)) (function_item name: (identifier) parameters: (parameters) body: (block)))" )
135135
136- structNode := rootNode .Child (0 )
136+ structNode := nodeMust ( rootNode .Child (0 ) )
137137 assert .Equal (t , structNode .Kind (), "struct_item" )
138138}
139139
@@ -232,7 +232,7 @@ func TestParsingWithCustomUTF8Input(t *testing.T) {
232232 assert .Equal (t , root .ToSexp (), "(source_file (function_item (visibility_modifier) name: (identifier) parameters: (parameters) body: (block (integer_literal))))" )
233233 assert .Equal (t , root .Kind (), "source_file" )
234234 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" )
236236}
237237
238238func TestParsingWithCustomUTF16LEInput (t * testing.T ) {
@@ -266,7 +266,7 @@ func TestParsingWithCustomUTF16LEInput(t *testing.T) {
266266 assert .Equal (t , root .ToSexp (), "(source_file (function_item (visibility_modifier) name: (identifier) parameters: (parameters) body: (block (integer_literal))))" )
267267 assert .Equal (t , root .Kind (), "source_file" )
268268 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" )
270270}
271271
272272func TestParsingWithCustomUTF16BEInput (t * testing.T ) {
@@ -311,7 +311,7 @@ func TestParsingWithCustomUTF16BEInput(t *testing.T) {
311311 assert .Equal (t , root .ToSexp (), "(source_file (function_item (visibility_modifier) name: (identifier) parameters: (parameters) body: (block (integer_literal))))" )
312312 assert .Equal (t , root .Kind (), "source_file" )
313313 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" )
315315}
316316
317317func TestParsingWithCallbackReturningOwnedStrings (t * testing.T ) {
@@ -717,7 +717,7 @@ func TestParsingWithTimeout(t *testing.T) {
717717 nil ,
718718 nil ,
719719 )
720- assert .Equal (t , "array" , tree .RootNode ().Child (0 ).Kind ())
720+ assert .Equal (t , "array" , nodeMust ( tree .RootNode ().Child (0 ) ).Kind ())
721721}
722722
723723func TestParsingWithTimeoutAndReset (t * testing.T ) {
@@ -753,7 +753,7 @@ func TestParsingWithTimeoutAndReset(t *testing.T) {
753753 // it does not see the changes to the beginning of the source code.
754754 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]" )
755755 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 ())
757757
758758 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]" )
759759 tree = parser .ParseWithOptions (
@@ -770,7 +770,7 @@ func TestParsingWithTimeoutAndReset(t *testing.T) {
770770 parser .Reset ()
771771 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]" )
772772 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 ())
774774}
775775
776776func TestParsingWithTimeoutAndImplicitReset (t * testing.T ) {
@@ -805,7 +805,7 @@ func TestParsingWithTimeoutAndImplicitReset(t *testing.T) {
805805 parser .SetLanguage (getLanguage ("json" ))
806806 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]" )
807807 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 ())
809809}
810810
811811func TestParsingWithTimeoutAndNoCompletion (t * testing.T ) {
@@ -951,7 +951,7 @@ func TestParsingWithOneIncludedRange(t *testing.T) {
951951 defer parser .Close ()
952952 parser .SetLanguage (getLanguage ("html" ))
953953 htmlTree := parser .Parse ([]byte (sourceCode ), nil )
954- scriptContentNode := htmlTree .RootNode ().Child (1 ).Child (1 )
954+ scriptContentNode := nodeMust ( nodeMust ( htmlTree .RootNode ().Child (1 )) .Child (1 ) )
955955 assert .Equal (t , "raw_text" , scriptContentNode .Kind ())
956956
957957 assert .Equal (t , []Range {
@@ -985,16 +985,16 @@ func TestParsingWithMultipleIncludedRanges(t *testing.T) {
985985 defer parser .Close ()
986986 parser .SetLanguage (getLanguage ("javascript" ))
987987 jsTree := parser .Parse ([]byte (sourceCode ), nil )
988- templateStringNode := jsTree .RootNode ().DescendantForByteRange (
988+ templateStringNode := nodeMust ( jsTree .RootNode ().DescendantForByteRange (
989989 uint (strings .Index (sourceCode , "`<" )),
990990 uint (strings .Index (sourceCode , ">`" )),
991- )
991+ ))
992992 assert .Equal (t , "template_string" , templateStringNode .Kind ())
993993
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 ) )
998998
999999 parser .SetLanguage (getLanguage ("html" ))
10001000 htmlRanges := []Range {
@@ -1027,11 +1027,11 @@ func TestParsingWithMultipleIncludedRanges(t *testing.T) {
10271027 )
10281028 assert .Equal (t , htmlRanges , htmlTree .IncludedRanges ())
10291029
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 ) )
10351035
10361036 assert .Equal (t , "text" , helloTextNode .Kind ())
10371037 assert .Equal (t , uint (strings .Index (sourceCode , "Hello" )), helloTextNode .StartByte ())
@@ -1164,8 +1164,8 @@ func TestParsingWithExternalScannerThatUsesIncludedRangeBoundaries(t *testing.T)
11641164 tree := parser .Parse ([]byte (sourceCode ), nil )
11651165 defer tree .Close ()
11661166 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 ) )
11691169
11701170 assert .Equal (
11711171 t ,
0 commit comments