From 401ab3ffeb322e4c2f9a4513c9422c6b062ddc66 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sat, 4 Nov 2023 13:22:31 +0100 Subject: parser: add tests for logical operatators --- parser/interpreter_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'parser') diff --git a/parser/interpreter_test.go b/parser/interpreter_test.go index a49eb96..9794337 100644 --- a/parser/interpreter_test.go +++ b/parser/interpreter_test.go @@ -62,6 +62,21 @@ func TestExpr(t *testing.T) { }) } +func TestLogical(t *testing.T) { + run(t, []etest{ + {src: "true && false", res: "false"}, + {src: "true && true", res: "true"}, + {src: "true && true && false", res: "false"}, + {src: "false || true && true", res: "true"}, + {src: "2 < 3 && 1 > 2 || 3 == 3", res: "true"}, + {src: "2 > 3 && 1 > 2 || 3 == 3", res: "true"}, + {src: "2 > 3 || 2 == 1+1 && 3>0", res: "true"}, + {src: "2 > 3 || 2 == 1+1 && 3>4 || 1<2", res: "true"}, + {src: "a := 1+1 < 3 && 4 == 2+2; a", res: "true"}, + {src: "a := 1+1 < 3 || 3 == 2+2; a", res: "true"}, + }) +} + func TestFunc(t *testing.T) { run(t, []etest{ {src: "func f() int {return 2}; a := f(); a", res: "2"}, -- cgit v1.2.3