From a3488207e657ddd8d044aec475bc7cd0a5274e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Ferr=C3=A0s?= Date: Wed, 4 Sep 2024 18:12:11 +0200 Subject: [PATCH] Fix for_statement test --- server/internal/lsp/ast/convert_statement.go | 3 ++- server/internal/lsp/ast/convert_statement_test.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/internal/lsp/ast/convert_statement.go b/server/internal/lsp/ast/convert_statement.go index d3745bc..df7761b 100644 --- a/server/internal/lsp/ast/convert_statement.go +++ b/server/internal/lsp/ast/convert_statement.go @@ -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") diff --git a/server/internal/lsp/ast/convert_statement_test.go b/server/internal/lsp/ast/convert_statement_test.go index 326ee87..270ecc8 100644 --- a/server/internal/lsp/ast/convert_statement_test.go +++ b/server/internal/lsp/ast/convert_statement_test.go @@ -567,7 +567,7 @@ func TestConvertToAST_for_stmt(t *testing.T) { }, }, { - skip: true, + skip: false, input: ` for (int i=0, j=0; true; i++) {}`, expected: ForStatement{ @@ -575,7 +575,7 @@ func TestConvertToAST_for_stmt(t *testing.T) { 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"). @@ -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{