aboutsummaryrefslogtreecommitdiff
path: root/parser/parser_test.go
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-04-04 14:46:58 +0000
committerBobby <[email protected]>2024-04-04 14:46:58 +0000
commit3d4f24f7c4ea05471109c0b13abbc95e70c6924b (patch)
tree5f4d07cf04336ff25e64b8ffc76a821e1b1861f5 /parser/parser_test.go
parent98b3baa1d9d05551948b6657b4130cf05c11934d (diff)
downloadmana-3d4f24f7c4ea05471109c0b13abbc95e70c6924b.tar.xz
mana-3d4f24f7c4ea05471109c0b13abbc95e70c6924b.zip
parsing array expressions
Diffstat (limited to 'parser/parser_test.go')
-rw-r--r--parser/parser_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 3a574a7..f1b8b8c 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -791,3 +791,28 @@ func TestStringLiteralExpression(t *testing.T) {
t.Errorf("literal.Value not %q. got=%q", "hello world", literal.Value)
}
}
+
+func TestParsingArrayLiterals(t *testing.T) {
+ input := "[1, 2 * 2, 3 + 3]"
+
+ var l *lexer.Lexer = lexer.New(input)
+ var p *Parser = New(l)
+
+ var program *ast.Program = p.ParseProgram()
+ checkParserErrors(t, p)
+
+ stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
+ array, ok := stmt.Expression.(*ast.ArrayLiteral)
+
+ if !ok {
+ t.Fatalf("exp is not ast.ArrayLiteral. got=%T", stmt.Expression)
+ }
+
+ if len(array.Elements) != 3 {
+ t.Fatalf("len(array.Elements) not 3. got=%d", len(array.Elements))
+ }
+
+ testIntegerLiteral(t, array.Elements[0], 1)
+ testInfixExpression(t, array.Elements[1], 2, "*", 2)
+ testInfixExpression(t, array.Elements[2], 3, "+", 3)
+}