about summary refs log tree commit diff
path: root/pkg/lang/parser/parser_test.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-06-14 00:07:40 +0000
committerGitHub <noreply@github.com>2022-06-14 00:07:40 +0000
commit3498876f06104515002191468fd99019d40051c2 (patch)
tree7f1c3a34fe442382c82519a94ae089f22e252f71 /pkg/lang/parser/parser_test.go
parent14bdb59c24aef85f2a7c69f03ddacb7f56445e9e (diff)
downloadjinx-3498876f06104515002191468fd99019d40051c2.tar.zst
jinx-3498876f06104515002191468fd99019d40051c2.zip
Fix BinExpr precendence not being drilled down
Diffstat (limited to 'pkg/lang/parser/parser_test.go')
-rw-r--r--pkg/lang/parser/parser_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/pkg/lang/parser/parser_test.go b/pkg/lang/parser/parser_test.go
index c3794e9..64dd67a 100644
--- a/pkg/lang/parser/parser_test.go
+++ b/pkg/lang/parser/parser_test.go
@@ -98,6 +98,57 @@ func TestLeftAssocBinaryExpr(t *testing.T) {
 	}, program.Stmts[0])
 }
 
+func TestLeftAssocBinary4Expr(t *testing.T) {
+	src := `1 + 2 - 3 + 4`
+	p := cheatWithScanner(t, src)
+	program, err := p.Parse()
+	require.NoError(t, err)
+
+	require.Equal(t, 1, len(program.Stmts))
+	require.Equal(t, ast.Stmt{
+		Kind: 11,
+		Value: ast.StmtExpr{
+			Value: ast.Expr{
+				Kind: ast.ExprKindBinary,
+				Value: ast.ExprBinary{
+					Left: ast.Expr{
+						Kind: ast.ExprKindBinary,
+						Value: ast.ExprBinary{
+							Left: ast.Expr{
+								Kind: ast.ExprKindBinary,
+								Value: ast.ExprBinary{
+									Left: ast.Expr{
+										Kind:  ast.ExprKindIntLit,
+										Value: ast.ExprIntLit{Value: 1},
+									},
+									Op: ast.BinOpPlus,
+									Right: ast.Expr{
+										At:    source.NewLoc(0, 4),
+										Kind:  ast.ExprKindIntLit,
+										Value: ast.ExprIntLit{Value: 2},
+									},
+								},
+							},
+							Op: ast.BinOpMinus,
+							Right: ast.Expr{
+								At:    source.NewLoc(0, 8),
+								Kind:  ast.ExprKindIntLit,
+								Value: ast.ExprIntLit{Value: 3},
+							},
+						},
+					},
+					Op: ast.BinOpPlus,
+					Right: ast.Expr{
+						At:    source.NewLoc(0, 12),
+						Kind:  ast.ExprKindIntLit,
+						Value: ast.ExprIntLit{Value: 4},
+					},
+				},
+			},
+		},
+	}, program.Stmts[0])
+}
+
 func TestRightAssocBinaryExpr(t *testing.T) {
 	src := `x = y = z`
 	p := cheatWithScanner(t, src)