aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-12-20 08:44:19 +0100
committerGitHub <noreply@github.com>2022-12-20 07:44:19 +0000
commitd26553491b3efb3fce7cc626683342cd1fa4cbf3 (patch)
tree7edeafe8cb4454f83357d72c707556dedd026df4 /tests
parentfeat(functional): add trim_start and assoc (#779) (diff)
downloadmason-d26553491b3efb3fce7cc626683342cd1fa4cbf3.tar
mason-d26553491b3efb3fce7cc626683342cd1fa4cbf3.tar.gz
mason-d26553491b3efb3fce7cc626683342cd1fa4cbf3.tar.bz2
mason-d26553491b3efb3fce7cc626683342cd1fa4cbf3.tar.lz
mason-d26553491b3efb3fce7cc626683342cd1fa4cbf3.tar.xz
mason-d26553491b3efb3fce7cc626683342cd1fa4cbf3.tar.zst
mason-d26553491b3efb3fce7cc626683342cd1fa4cbf3.zip
feat(expr): use same context for value & filter evaluation (#778)
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-core/installer/registry/expr_spec.lua34
1 files changed, 30 insertions, 4 deletions
diff --git a/tests/mason-core/installer/registry/expr_spec.lua b/tests/mason-core/installer/registry/expr_spec.lua
index 7e662b79..ec92f7a7 100644
--- a/tests/mason-core/installer/registry/expr_spec.lua
+++ b/tests/mason-core/installer/registry/expr_spec.lua
@@ -4,7 +4,7 @@ local Result = require "mason-core.result"
describe("registry expressions", function()
it("should eval simple expressions", function()
- assert.same(Result.success "Hello, world!", expr.eval "Hello, world!")
+ assert.same(Result.success "Hello, world!", expr.eval("Hello, world!", {}))
assert.same(
Result.success "Hello, John Doe!",
@@ -15,6 +15,34 @@ describe("registry expressions", function()
)
end)
+ it("should eval nested access", function()
+ assert.same(
+ Result.success "Hello, world!",
+ expr.eval("Hello, {{greeting.name}}!", { greeting = { name = "world" } })
+ )
+ end)
+
+ it("should eval benign expressions", function()
+ assert.same(
+ Result.success "Hello, JOHNDOE JR.!",
+ expr.eval("Hello, {{greeting.firstname .. greeting.lastname .. tostring(tbl) | to_upper}}!", {
+ greeting = { firstname = "John", lastname = "Doe" },
+ tbl = setmetatable({}, {
+ __tostring = function()
+ return " Jr."
+ end,
+ }),
+ })
+ )
+
+ assert.same(
+ Result.success "Gloves",
+ expr.eval("G{{ 'Cloves' | trim_start(trim) }}", {
+ trim = "C",
+ })
+ )
+ end)
+
it("should eval expressions with filters", function()
assert.same(
Result.success "Hello, MR. John!",
@@ -35,9 +63,7 @@ describe("registry expressions", function()
it("should reject invalid values", function()
assert.is_true(
- match.matches [[^.*Unable to interpolate value: "non_existent"%.$]](
- expr.eval("Hello, {{non_existent}}", {}):err_or_nil()
- )
+ match.matches [[^.*Value is nil: "non_existent"%.$]](expr.eval("Hello, {{non_existent}}", {}):err_or_nil())
)
end)