Skip to content

Commit

Permalink
Fix for_statement test
Browse files Browse the repository at this point in the history
  • Loading branch information
pherrymason committed Sep 4, 2024
1 parent 23ff370 commit e939c6d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/internal/lsp/ast/convert_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r SequenceOf) Validate(node *sitter.Node, source []byte) bool {
siblings++
}

if siblings != len(r.ExpectedSequence) {
if siblings < len(r.ExpectedSequence) {
return false
}

Expand Down
4 changes: 3 additions & 1 deletion server/internal/lsp/ast/convert_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func convert_declaration_stmt(node *sitter.Node, source []byte) Expression {
varDecl := VariableDecl{
ASTBaseNode: NewBaseNodeFromSitterNode(node),
}
for i := 0; i < int(node.ChildCount()); i++ {
end := false
for i := 0; i < int(node.ChildCount()) && !end; i++ {
n := node.Child(i)
debugNode(n, source, "dd")

Expand Down Expand Up @@ -107,6 +108,7 @@ func convert_declaration_stmt(node *sitter.Node, source []byte) Expression {
if right != nil {
varDecl.Initializer = convert_expression(right, source)
}
end = true
}
}

Expand Down
13 changes: 11 additions & 2 deletions server/internal/lsp/ast/convert_statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,15 @@ func TestConvertToAST_for_stmt(t *testing.T) {
},
},
{
skip: true,
skip: false,
input: `
for (int i=0, j=0; true; i++) {}`,
expected: ForStatement{
ASTBaseNode: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 35).Build(),
Label: option.None[string](),
Initializer: []Expression{
VariableDecl{
ASTBaseNode: NewBaseNodeBuilder().WithStartEnd(3, 8, 3, 15).Build(),
ASTBaseNode: NewBaseNodeBuilder().WithStartEnd(3, 8, 3, 20).Build(),
Names: []Identifier{
NewIdentifierBuilder().
WithName("i").
Expand All @@ -592,6 +592,15 @@ func TestConvertToAST_for_stmt(t *testing.T) {
Value: "0",
},
},
AssignmentStatement{
ASTBaseNode: NewBaseNodeBuilder().WithStartEnd(3, 17, 3, 20).Build(),
Left: NewIdentifierBuilder().
WithName("j").
WithStartEnd(3, 17, 3, 18).
Build(),
Right: IntegerLiteral{Value: "0"},
Operator: "=",
},
},
Condition: BoolLiteral{Value: true},
Update: []Expression{
Expand Down

0 comments on commit e939c6d

Please sign in to comment.