From 77e45404ad509552cddb39a426b7746b7b35c24d Mon Sep 17 00:00:00 2001 From: Remco Westerhoud Date: Thu, 17 Aug 2023 14:26:43 +0200 Subject: [PATCH] test: verify filtering list of contexts This commit adds some testcases to verify filtering over a list of contexts works as intended. It focuses on cases where something in the contexts, or filter is non-existing or null. --- .../InterpreterContextExpressionTest.scala | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala index 4a12f37e8..716d61dc6 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala @@ -75,7 +75,7 @@ class InterpreterContextExpressionTest val items = list.asInstanceOf[ValList].items items should have size 1 - val context = items(0) + val context = items.head context .asInstanceOf[ValContext] @@ -84,6 +84,68 @@ class InterpreterContextExpressionTest .getVariables should be(Map("a" -> ValNumber(3), "b" -> ValNumber(4))) } + it should "be filtered via comparison with missing entry" in { + + val list = eval("[{x: 1, y: 2}, {x: 3}][y > 1]") + list shouldBe a[ValList] + + val items = list.asInstanceOf[ValList].items + items should have size 1 + val context = items.head + + context + .asInstanceOf[ValContext] + .context + .variableProvider + .getVariables should be(Map("x" -> ValNumber(1), "y" -> ValNumber(2))) + } + + it should "be filtered via comparison with null value" in { + val list = eval("[{x: 1}, {x: null}][x > 0]") + list shouldBe a[ValList] + + val items = list.asInstanceOf[ValList].items + items should have size 1 + val context = items.head + + context + .asInstanceOf[ValContext] + .context + .variableProvider + .getVariables should be(Map("x" -> ValNumber(1))) + } + + it should "be filtered via matching null comparison" in { + val list = eval("[{x: 1}, {x: null}][x = null]") + list shouldBe a[ValList] + + val items = list.asInstanceOf[ValList].items + items should have size 1 + val context = items.head + + context + .asInstanceOf[ValContext] + .context + .variableProvider + .getVariables should be(Map("x" -> ValNull)) + } + + // note that a missing entry is equivalent to that entry containing null + it should "be filtered via missing entry null comparison" in { + val list = eval("[{x: 1}, {y: 1}][x = null]") + list shouldBe a[ValList] + + val items = list.asInstanceOf[ValList].items + items should have size 1 + val context = items.head + + context + .asInstanceOf[ValContext] + .context + .variableProvider + .getVariables should be(Map("y" -> ValNumber(1))) + } + it should "be filtered by name 'item'" in { eval("[ {item:1}, {item:2}, {item:3} ][item >= 2]") match {