Skip to content

Commit 41be554

Browse files
authored
Merge pull request #969 from camunda/27004-unary-test
fix: A unary-test expression returns null instead of false
2 parents 61a5064 + b2edd82 commit 41be554

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

src/main/scala/org/camunda/feel/impl/interpreter/FeelInterpreter.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ class FeelInterpreter(private val valueMapper: ValueMapper) {
672672
case ValBoolean(true) =>
673673
// the expression is the input value
674674
ValBoolean(true)
675+
case _ if x == ValBoolean(false) =>
676+
// the expression is false
677+
ValBoolean(false)
675678
case _ if x.isInstanceOf[ValList] =>
676679
// the expression is a list but doesn't contain the input value
677680
ValBoolean(false)

src/test/scala/org/camunda/feel/impl/interpreter/InterpreterUnaryTest.scala

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,4 +655,119 @@ class InterpreterUnaryTest
655655
evaluateUnaryTests("5 < ? or ? < 10", inputValue = null) should returnNull()
656656
}
657657

658+
it should "return true if it evaluates to true" in {
659+
660+
evaluateUnaryTests("x", inputValue = 3, variables = Map("x" -> true)) should returnResult(true)
661+
evaluateUnaryTests("4 < 10", 3) should returnResult(true)
662+
evaluateUnaryTests("even(4)", 3) should returnResult(true)
663+
evaluateUnaryTests("list contains([1,2,3], 3)", 3) should returnResult(true)
664+
}
665+
666+
it should "return false if it evaluates to false" in {
667+
668+
evaluateUnaryTests(
669+
expression = "x",
670+
inputValue = 3,
671+
variables = Map("x" -> false)
672+
) should returnResult(false)
673+
evaluateUnaryTests(expression = "4 > 10", 3) should returnResult(false)
674+
evaluateUnaryTests(expression = "odd(4)", 3) should returnResult(false)
675+
evaluateUnaryTests(expression = "list contains([1,2], 3)", 3) should returnResult(false)
676+
}
677+
678+
"A negation" should "return true if it evaluates to a value that is not equal to the implicit value" in {
679+
680+
evaluateUnaryTests("not(1)", 3) should returnResult(true)
681+
evaluateUnaryTests(""" not("a") """, "b") should returnResult(true)
682+
}
683+
684+
it should "return false if it evaluates to a value that is equal to the implicit value" in {
685+
686+
evaluateUnaryTests("not(3)", 3) should returnResult(false)
687+
evaluateUnaryTests(""" not("b") """, "b") should returnResult(false)
688+
}
689+
690+
it should "return null if it evaluates to a value that has a different type than the implicit value" in {
691+
692+
evaluateUnaryTests("not(1)", "b") should returnNull()
693+
evaluateUnaryTests(""" not("a") """, 2) should returnNull()
694+
}
695+
696+
it should "return true if it evaluates to false when the implicit value is applied to it" in {
697+
698+
evaluateUnaryTests("not(< 3)", 5) should returnResult(true)
699+
evaluateUnaryTests("not([1..3])", 5) should returnResult(true)
700+
evaluateUnaryTests("not(> x)", inputValue = 5, variables = Map("x" -> 10)) should returnResult(
701+
true
702+
)
703+
}
704+
705+
it should "return false if it evaluates to true when the implicit value is applied to it" in {
706+
707+
evaluateUnaryTests("not(< 10)", 5) should returnResult(false)
708+
evaluateUnaryTests("not([1..10])", 5) should returnResult(false)
709+
evaluateUnaryTests("not(> x)", inputValue = 5, variables = Map("x" -> 3)) should returnResult(
710+
false
711+
)
712+
}
713+
714+
it should "return null if it evaluates to null when the implicit value is applied to it" in {
715+
716+
evaluateUnaryTests("not(< 3)", "a") should returnNull()
717+
evaluateUnaryTests("not(< 3)", inputValue = null) should returnNull()
718+
}
719+
720+
it should "return true if it evaluates to false" in {
721+
722+
evaluateUnaryTests("not(x)", inputValue = 3, variables = Map("x" -> false)) should returnResult(
723+
true
724+
)
725+
evaluateUnaryTests("not(4 > 10)", 3) should returnResult(true)
726+
evaluateUnaryTests("not(odd(4))", 3) should returnResult(true)
727+
evaluateUnaryTests("not(list contains([1,2], 3))", 3) should returnResult(true)
728+
}
729+
730+
it should "return false if it evaluates to true" in {
731+
732+
evaluateUnaryTests("not(x)", inputValue = 3, variables = Map("x" -> true)) should returnResult(
733+
false
734+
)
735+
evaluateUnaryTests("not(4 < 10)", 3) should returnResult(false)
736+
evaluateUnaryTests("not(even(4))", 3) should returnResult(false)
737+
evaluateUnaryTests("not(list contains([1,2,3], 3))", 3) should returnResult(false)
738+
}
739+
740+
it should "return true if it evaluates to null and the implicit value is not null" in {
741+
742+
evaluateUnaryTests("not(null)", 5) should returnResult(true)
743+
evaluateUnaryTests("not(not_existing)", 5) should returnResult(true)
744+
}
745+
746+
it should "return false if it evaluates to null and the implicit value is null" in {
747+
748+
evaluateUnaryTests("not(null)", inputValue = null) should returnResult(false)
749+
evaluateUnaryTests("not(not_existing)", inputValue = null) should returnResult(false)
750+
}
751+
752+
it should "return true if a disjunction evaluates to false" in {
753+
754+
evaluateUnaryTests("not(2,3)", 5) should returnResult(true)
755+
evaluateUnaryTests("not(< 3, > 10)", 5) should returnResult(true)
756+
evaluateUnaryTests("not([0..3], [10..20])", 5) should returnResult(true)
757+
}
758+
759+
it should "return false if a disjunction evaluates to true" in {
760+
761+
evaluateUnaryTests("not(2,3)", 3) should returnResult(false)
762+
evaluateUnaryTests("not(< 3, > 10)", 1) should returnResult(false)
763+
evaluateUnaryTests("not([0..3], [10..20])", 1) should returnResult(false)
764+
}
765+
766+
it should "return null if a disjunction evaluates to null" in {
767+
768+
evaluateUnaryTests("not(2,3)", "a") should returnNull()
769+
evaluateUnaryTests("not(< 3, > 10)", "a") should returnNull()
770+
evaluateUnaryTests("not([0..3], [10..20])", "a") should returnNull()
771+
}
772+
658773
}

0 commit comments

Comments
 (0)