From 9990208f4208d724f13459a489e4740c30a26b1c Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Wed, 15 Jun 2022 12:08:25 +0200 Subject: [PATCH 1/4] test: verify unary-tests with boolean conjunction/disjunction --- .../feel/impl/interpreter/InterpreterUnaryTest.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala index 53b2ed2ea..cdbe3ec54 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala @@ -182,6 +182,17 @@ class InterpreterUnaryTest evalUnaryTests(true, """ "a" = "b" """) should be(ValBoolean(false)) } + it should "compare to a conjunction (and)" in { + evalUnaryTests(true, "true and true") shouldBe ValBoolean(true) + evalUnaryTests(true, "false and true") shouldBe ValBoolean(false) + } + + it should "compare to a disjunction (or)" in { + evalUnaryTests(true, "true or true") shouldBe ValBoolean(true) + evalUnaryTests(true, "false or true") shouldBe ValBoolean(true) + evalUnaryTests(true, "false or false") shouldBe ValBoolean(false) + } + "A date" should "compare with '<'" in { evalUnaryTests(date("2015-09-17"), """< date("2015-09-18")""") should be( From 7ef5c55acaf1e7d7169e0d8619a608ce99538b5a Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Wed, 15 Jun 2022 12:12:49 +0200 Subject: [PATCH 2/4] fix: parse unary-tests with conjunction/disjunction * a unary-tests expression with a boolean literal and a conjunction/disjunction failed to parse * the parser expected no other chars (EOF) after the boolean literal was accepted * adjust the parser to accept the boolean literal only at the end of the expression (EOF) --- src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala b/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala index 7b1bb289b..e1fed305a 100644 --- a/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala +++ b/src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala @@ -574,7 +574,7 @@ object FeelParser { // boolean literals are ambiguous for unary-tests. give precedence to comparison with input. private def positiveUnaryTest[_: P]: P[Exp] = - boolean.map(InputEqualTo) | expression.map(UnaryTestExpression) + (boolean.map(InputEqualTo) ~ End) | expression.map(UnaryTestExpression) private def anyInput[_: P]: P[Exp] = P( From 78394491e41ffceb1a22f70c6f66f89c256292f3 Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Fri, 24 Jun 2022 06:02:11 +0200 Subject: [PATCH 3/4] test: add additional test cases --- .../impl/interpreter/InterpreterUnaryTest.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala index cdbe3ec54..4d2cc0cde 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala @@ -185,12 +185,27 @@ class InterpreterUnaryTest it should "compare to a conjunction (and)" in { evalUnaryTests(true, "true and true") shouldBe ValBoolean(true) evalUnaryTests(true, "false and true") shouldBe ValBoolean(false) + + evalUnaryTests(true, "true and null") shouldBe ValBoolean(false) + evalUnaryTests(true, "false and null") shouldBe ValBoolean(false) + + evalUnaryTests(true, """true and "otherwise" """) shouldBe ValBoolean( + false) + evalUnaryTests(true, """false and "otherwise" """) shouldBe ValBoolean( + false) } it should "compare to a disjunction (or)" in { evalUnaryTests(true, "true or true") shouldBe ValBoolean(true) evalUnaryTests(true, "false or true") shouldBe ValBoolean(true) evalUnaryTests(true, "false or false") shouldBe ValBoolean(false) + + evalUnaryTests(true, "true or null") shouldBe ValBoolean(true) + evalUnaryTests(true, "false or null") shouldBe ValBoolean(false) + + evalUnaryTests(true, """true or "otherwise" """) shouldBe ValBoolean(true) + evalUnaryTests(true, """false or "otherwise" """) shouldBe ValBoolean( + false) } "A date" should "compare with '<'" in { From 247b8b38be6d5ce43ab2d04483f621157dcaadd1 Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Wed, 29 Jun 2022 05:24:01 +0200 Subject: [PATCH 4/4] docs: add comment to test cases --- .../camunda/feel/impl/interpreter/InterpreterUnaryTest.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala index 4d2cc0cde..2d23f4124 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala @@ -183,6 +183,7 @@ class InterpreterUnaryTest } it should "compare to a conjunction (and)" in { + // it is uncommon to use a conjunction in a unary-tests but the engine should be able to parse evalUnaryTests(true, "true and true") shouldBe ValBoolean(true) evalUnaryTests(true, "false and true") shouldBe ValBoolean(false) @@ -196,6 +197,7 @@ class InterpreterUnaryTest } it should "compare to a disjunction (or)" in { + // it is uncommon to use a disjunction in a unary-tests but the engine should be able to parse evalUnaryTests(true, "true or true") shouldBe ValBoolean(true) evalUnaryTests(true, "false or true") shouldBe ValBoolean(true) evalUnaryTests(true, "false or false") shouldBe ValBoolean(false)