Skip to content

Commit

Permalink
fix(engine): list projection with variable (#385)
Browse files Browse the repository at this point in the history
* fix path expression for list of contexts (i.e. list projection) with variable reference
* it worked previously because it was parsed as a `path` expression instead of a `ref` expression
  • Loading branch information
saig0 committed Jan 4, 2022
1 parent 04cfe39 commit 1d3147f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -978,17 +978,9 @@ class FeelInterpreter {
names match {
case Nil => x
case n :: ns =>
withContext(
x, {
case ctx: ValContext =>
EvalContext
.wrap(ctx.context)(context.valueMapper)
.variable(n) match {
case e: ValError => e
case x: Val => ref(x, ns)
}
case e => error(e, s"context contains no entry with key '$n'")
}
withVal(
path(x, n),
value => ref(value, ns)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ class InterpreterContextExpressionTest
eval("{ a: { b:1 } }.a.b") should be(ValNumber(1))
}

it should "be accessed in a list" in {
it should "be accessed in a list (literal)" in {

eval("[ {a:1, b:2}, {a:3, b:4} ].a") should be(
ValList(List(ValNumber(1), ValNumber(3))))
}

it should "be accessed in a list (variable)" in {
eval("a.b", Map("a" -> List(Map("b" -> 1), Map("b" -> 2)))) should be(
ValList(List(ValNumber(1), ValNumber(2))))
}

it should "be accessed in same context" in {

eval("{ a:1, b:(a+1), c:(b+1)}.c") should be(ValNumber(3))
Expand Down

0 comments on commit 1d3147f

Please sign in to comment.