aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-03-05 02:45:00 +0100
committerGitHub <noreply@github.com>2023-03-05 02:45:00 +0100
commit5887ce1c8031fb15e5cdcf43999db01b19536d6e (patch)
tree9cb37a72e28e61d84e5ffa7fdbef33ef394b1531 /tests
parentfeat(InstallContext): add strict_mode flag (#1055) (diff)
downloadmason-5887ce1c8031fb15e5cdcf43999db01b19536d6e.tar
mason-5887ce1c8031fb15e5cdcf43999db01b19536d6e.tar.gz
mason-5887ce1c8031fb15e5cdcf43999db01b19536d6e.tar.bz2
mason-5887ce1c8031fb15e5cdcf43999db01b19536d6e.tar.lz
mason-5887ce1c8031fb15e5cdcf43999db01b19536d6e.tar.xz
mason-5887ce1c8031fb15e5cdcf43999db01b19536d6e.tar.zst
mason-5887ce1c8031fb15e5cdcf43999db01b19536d6e.zip
refactor(expr): better handling of nil values (#1056)
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-core/installer/registry/expr_spec.lua19
1 files changed, 11 insertions, 8 deletions
diff --git a/tests/mason-core/installer/registry/expr_spec.lua b/tests/mason-core/installer/registry/expr_spec.lua
index a52ca48b..c628381a 100644
--- a/tests/mason-core/installer/registry/expr_spec.lua
+++ b/tests/mason-core/installer/registry/expr_spec.lua
@@ -61,12 +61,16 @@ describe("registry expressions", function()
)
end)
- it("should reject invalid values", function()
- assert.is_true(
- match.matches [[^.*Value is nil: "non_existent"]](
- expr.interpolate("Hello, {{non_existent}}", {}):err_or_nil()
- )
- )
+ it("should not interpolate nil values", function()
+ assert.same(Result.success "Hello, ", expr.interpolate("Hello, {{non_existent}}", {}))
+ assert.same(Result.success "", expr.interpolate("{{non_existent}}", {}))
+ end)
+
+ it("should error if piping nil values to functions that require non-nil values", function()
+ local err = assert.has_error(function()
+ expr.interpolate("Hello, {{ non_existent | to_upper }}", {}):get_or_throw()
+ end)
+ assert.is_true(match.matches "attempt to index local 'str' %(a nil value%)$"(err))
end)
it("should reject invalid filters", function()
@@ -75,9 +79,8 @@ describe("registry expressions", function()
expr.interpolate("Hello, {{ value | whut }}", { value = "value" }):err_or_nil()
)
)
-
assert.is_true(
- match.matches [[^.*Failed to parse filter: "wh%-!uut"]](
+ match.matches [[^.*Failed to parse expression: "wh%-!uut"]](
expr.interpolate("Hello, {{ value | wh-!uut }}", { value = "value" }):err_or_nil()
)
)