diff options
Diffstat (limited to 'pkg/lang/parser/parser_test.go')
| -rw-r--r-- | pkg/lang/parser/parser_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/pkg/lang/parser/parser_test.go b/pkg/lang/parser/parser_test.go index e02ab5a..8cecfa8 100644 --- a/pkg/lang/parser/parser_test.go +++ b/pkg/lang/parser/parser_test.go @@ -521,6 +521,50 @@ func TestForCondStmt(t *testing.T) { }, program.Stmts[0]) } +func TestEmptyForStmt(t *testing.T) { + src := sourceify( + `for {`, + ` "spam"`, + `}`, + ) + + 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.StmtKindForCond, + Value: ast.StmtForCond{ + Cond: ast.Expr{}, + Do: ast.BlockNode{ + At: source.NewLoc(0, 4), + Stmts: []ast.Stmt{ + { + At: source.NewLoc(0, 5), + Kind: ast.StmtKindEmpty, + Value: ast.StmtEmpty{}, + }, + { + At: source.NewLoc(1, 1), + Kind: ast.StmtKindExpr, + Value: ast.StmtExpr{ + Value: ast.Expr{ + At: source.NewLoc(1, 1), + Kind: ast.ExprKindStringLit, + Value: ast.ExprStringLit{ + Value: "spam", + }, + }, + }, + }, + }, + }, + }, + }, program.Stmts[0]) +} + func TestForInStmt(t *testing.T) { src := sourceify( `for x in [1, 2, 3] {`, |
