diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/installer/registry/expr_spec.lua | 34 |
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) |
