Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelkaczor committed Jan 24, 2021
1 parent 62991c5 commit d32d007
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Expand Up @@ -102,6 +102,7 @@ class ExpressionParserTest extends AnyFlatSpec with Matchers {

it should "parse comparison expressions with variables on both sides" in new Fixture {
verify(parser.parseBooleanExpression("""a == b"""), BigDecimalVar("a") == BigDecimalVar("b"))
verify(parser.parseBooleanExpression("""a != b"""), BigDecimalVar("a") != BigDecimalVar("b"))
verify(parser.parseBooleanExpression("""a > b"""), BigDecimalVar("a") > BigDecimalVar("b"))
}

Expand Down
24 changes: 18 additions & 6 deletions src/test/scala/br/com/virsox/scalexpr/ExpressionTest.scala
Expand Up @@ -141,13 +141,25 @@ class ExpressionTest extends AnyFlatSpec with Matchers {
(var1 + var2).resolve(context) shouldBe 40
}

it should "be used in relational expressions" in {
val var1 = IntVar("age")
val value = IntConstant(10)

it should "be used in arithmetic expressions with constants" in {
val intVar = IntVar("age")
val intValue = IntConstant(10)
val context: Map[String, Any] = Map("age" -> 19)
(var1 > value).resolve(context) shouldBe true
(var1 < value).resolve(context) shouldBe false

(intVar == intVar).resolve(context) shouldBe true
(intVar > intValue).resolve(context) shouldBe true
(intVar < intValue).resolve(context) shouldBe false
}

it should "be used in string comparisons" in {
val strVar = StringVar("name")
val strValue = StringConstant("John")
val context: Map[String, Any] = Map("name" -> "John")

(strVar == strVar).resolve(context) shouldBe true
(strVar != strVar).resolve(context) shouldBe false
(strVar != strValue).resolve(context) shouldBe false
(strVar != strValue).resolve(context) shouldBe false
}

// ---------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit d32d007

Please sign in to comment.