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

[Backport 1.16] fix: Function context put() works for more than two keys #903

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
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 @@ -150,10 +150,12 @@ class ContextBuiltinFunctions(valueMapper: ValueMapper) {
parentContextUpdater =
// pass a lambda to update this context with the modified nested context
nestedContext =>
contextPut(
contextValue = contextValue,
key = key,
value = nestedContext
parentContextUpdater(
contextPut(
contextValue = contextValue,
key = key,
value = nestedContext
)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,50 @@ class BuiltinContextFunctionsTest
evaluateExpression(""" context put({x:1, y:{a:1}}, ["y", "b"], 2) """) should returnResult(
Map("x" -> 1, "y" -> Map("a" -> 1, "b" -> 2))
)

evaluateExpression(
""" context put({x:1, a:{b:{c:1}}}, ["a", "b", "d"], 2) """
) should returnResult(
Map("x" -> 1, "a" -> Map("b" -> Map("c" -> 1, "d" -> 2)))
)

evaluateExpression(
""" context put({x:1, a:{b:{c:{d:1}}}}, ["a", "b", "c", "e"], 2) """
) should returnResult(
Map("x" -> 1, "a" -> Map("b" -> Map("c" -> Map("d" -> 1, "e" -> 2))))
)
}

it should "override nested context entry" in {
evaluateExpression(""" context put({x:1, y:{a:1}}, ["y", "a"], 2) """) should returnResult(
Map("x" -> 1, "y" -> Map("a" -> 2))
)

evaluateExpression(
""" context put({x:1, a:{b:{c:1}}}, ["a", "b", "c"], 2) """
) should returnResult(
Map("x" -> 1, "a" -> Map("b" -> Map("c" -> 2)))
)

evaluateExpression(
""" context put({x:1, a:{b:{c:{d:1}}}}, ["a", "b", "c", "d"], 2) """
) should returnResult(
Map("x" -> 1, "a" -> Map("b" -> Map("c" -> Map("d" -> 2))))
)
}

it should "add nested context entry if key doesn't exist" in {
evaluateExpression(""" context put({x:1}, ["y", "z"], 2) """) should returnResult(
Map("x" -> 1, "y" -> Map("z" -> 2))
)

evaluateExpression(""" context put({x:1}, ["a", "b", "c"], 2) """) should returnResult(
Map("x" -> 1, "a" -> Map("b" -> Map("c" -> 2)))
)

evaluateExpression(""" context put({x:1}, ["a", "b", "c", "d"], 2) """) should returnResult(
Map("x" -> 1, "a" -> Map("b" -> Map("c" -> Map("d" -> 2))))
)
}

it should "override nested context entry if existing value is not a context" in {
Expand Down
Loading