From 895120776a0ae4dd121029f1730d29ca886e201e Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 28 Jul 2022 21:18:09 +0000 Subject: Fix nested stacked exprs and parse members --- pkg/lang/parser/parser_test.go | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'pkg/lang/parser/parser_test.go') diff --git a/pkg/lang/parser/parser_test.go b/pkg/lang/parser/parser_test.go index de97928..24f3044 100644 --- a/pkg/lang/parser/parser_test.go +++ b/pkg/lang/parser/parser_test.go @@ -370,6 +370,55 @@ func TestMultipleStmts(t *testing.T) { require.Equal(t, expected, program.Stmts) } +func TestRepeatingNestedExpr(t *testing.T) { + src := "x.y.z()()" + + p := cheatWithScanner(t, src) + program, err := p.Parse() + require.NoError(t, err) + + require.Equal(t, 1, len(program.Stmts)) + require.Equal(t, ast.Stmt{ + At: source.NewLoc(0, 0), + Kind: ast.StmtKindExpr, + Value: ast.StmtExpr{ + Value: ast.Expr{ + At: source.NewLoc(0, 0), + Kind: ast.ExprKindCall, + Value: ast.ExprCall{ + Callee: ast.Expr{ + At: source.NewLoc(0, 0), + Kind: ast.ExprKindCall, + Value: ast.ExprCall{ + Callee: ast.Expr{ + At: source.NewLoc(0, 0), + Kind: ast.ExprKindMember, + Value: ast.ExprMember{ + Obj: ast.Expr{ + At: source.NewLoc(0, 0), + Kind: ast.ExprKindMember, + Value: ast.ExprMember{ + Obj: ast.Expr{ + At: source.NewLoc(0, 0), + Kind: ast.ExprKindIdent, + Value: ast.ExprIdent{Value: ast.IdentNode{At: source.NewLoc(0, 0), Value: "x"}}, + }, + Key: ast.IdentNode{At: source.NewLoc(0, 2), Value: "y"}, + }, + }, + Key: ast.IdentNode{At: source.NewLoc(0, 4), Value: "z"}, + }, + }, + Args: []ast.Expr{}, + }, + }, + Args: []ast.Expr{}, + }, + }, + }, + }, program.Stmts[0]) +} + func TestIfStmt(t *testing.T) { src := sourceify( `if false {`, -- cgit 1.4.1