Skip to content

Commit

Permalink
Parse unary-tests expression with boolean and conjunction/disjunction (
Browse files Browse the repository at this point in the history
…#435)

* test: verify unary-tests with boolean conjunction/disjunction

* 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)

* test: add additional test cases

* docs: add comment to test cases
  • Loading branch information
saig0 committed Jun 29, 2022
1 parent 7526ea0 commit ee8d47c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -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(
Expand Down
Expand Up @@ -182,6 +182,34 @@ class InterpreterUnaryTest
evalUnaryTests(true, """ "a" = "b" """) should be(ValBoolean(false))
}

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)

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 {
// 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)

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 {

evalUnaryTests(date("2015-09-17"), """< date("2015-09-18")""") should be(
Expand Down

0 comments on commit ee8d47c

Please sign in to comment.