aboutsummaryrefslogtreecommitdiff
path: root/parser/parser_test.go
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-02-03 05:19:30 -0500
committerBobby <[email protected]>2024-02-03 05:19:30 -0500
commitfebcc8807295c84ec8755b2468cc943cfa882a59 (patch)
tree9d3f04da65846a0a8f18fe28f255992ebf3d28f2 /parser/parser_test.go
parent9e1adf759c52595b9b8eaba1376ebb8d1eeb77e5 (diff)
downloadmana-febcc8807295c84ec8755b2468cc943cfa882a59.tar.xz
mana-febcc8807295c84ec8755b2468cc943cfa882a59.zip
CallExpressions Implemented. Parser Done
Diffstat (limited to 'parser/parser_test.go')
-rw-r--r--parser/parser_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 415b8cb..cd38144 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -510,6 +510,18 @@ func TestOperatorPrecedenceParsing(t *testing.T) {
"3 < 5 == true",
"((3 < 5) == true)",
},
+ {
+ "a + add(b * c) + d",
+ "((a + add((b * c))) + d)",
+ },
+ {
+ "add(a, b, 1, 2 * 3, 4 + 5, add(6, 7 * 8))",
+ "add(a, b, 1, (2 * 3), (4 + 5), add(6, (7 * 8)))",
+ },
+ {
+ "add(a + b + c * d / f + g)",
+ "add((((a + b) + ((c * d) / f)) + g))",
+ },
}
for _, tt := range tests {
@@ -726,3 +738,40 @@ func TestFunctionParameterParsing(t *testing.T) {
}
}
}
+
+func TestCallExpressionParsing(t *testing.T) {
+ var input string = "add(1, 2 * 3, 4 + 5);"
+
+ var l *lexer.Lexer = lexer.New(input)
+ var p *Parser = New(l)
+ var program *ast.Program = p.ParseProgram()
+ checkParserErrors(t, p)
+
+ if len(program.Statements) != 1 {
+ t.Fatalf("program.Statements does not contain %d statements. got=%d", 1, len(program.Statements))
+ }
+
+ stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
+
+ if !ok {
+ t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0])
+ }
+
+ exp, ok := stmt.Expression.(*ast.CallExpression)
+
+ if !ok {
+ t.Fatalf("stmt.Expression is not ast.CallExpression. got=%T", stmt.Expression)
+ }
+
+ if !testIdentifier(t, exp.Function, "add") {
+ return
+ }
+
+ if len(exp.Arguments) != 3 {
+ t.Fatalf("wrong length of arguments. got=%d", len(exp.Arguments))
+ }
+
+ testLiteralExpression(t, exp.Arguments[0], 1)
+ testInfixExpression(t, exp.Arguments[1], 2, "*", 3)
+ testInfixExpression(t, exp.Arguments[2], 4, "+", 5)
+}