Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify filtering list of contexts where some part is null or non-existing #700

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 {
Expand Down