From ee75fcd37eaecbc5db479eb648c41a7d11144e32 Mon Sep 17 00:00:00 2001 From: William Boman Date: Mon, 2 Jan 2023 06:52:45 +0100 Subject: refactor(expr): rename to interpolate (#836) --- tests/mason-core/installer/registry/expr_spec.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/mason-core/installer/registry/expr_spec.lua b/tests/mason-core/installer/registry/expr_spec.lua index abd1874e..a52ca48b 100644 --- a/tests/mason-core/installer/registry/expr_spec.lua +++ b/tests/mason-core/installer/registry/expr_spec.lua @@ -4,11 +4,11 @@ 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.interpolate("Hello, world!", {})) assert.same( Result.success "Hello, John Doe!", - expr.eval("Hello, {{firstname}} {{ lastname }}!", { + expr.interpolate("Hello, {{firstname}} {{ lastname }}!", { firstname = "John", lastname = "Doe", }) @@ -18,14 +18,14 @@ describe("registry expressions", function() it("should eval nested access", function() assert.same( Result.success "Hello, world!", - expr.eval("Hello, {{greeting.name}}!", { greeting = { name = "world" } }) + expr.interpolate("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}}!", { + expr.interpolate("Hello, {{greeting.firstname .. greeting.lastname .. tostring(tbl) | to_upper}}!", { greeting = { firstname = "John", lastname = "Doe" }, tbl = setmetatable({}, { __tostring = function() @@ -37,7 +37,7 @@ describe("registry expressions", function() assert.same( Result.success "Gloves", - expr.eval("G{{ 'Cloves' | strip_prefix(trim) }}", { + expr.interpolate("G{{ 'Cloves' | strip_prefix(trim) }}", { trim = "C", }) ) @@ -46,7 +46,7 @@ describe("registry expressions", function() it("should eval expressions with filters", function() assert.same( Result.success "Hello, MR. John!", - expr.eval("Hello, {{prefix|to_upper}} {{ name | trim }}!", { + expr.interpolate("Hello, {{prefix|to_upper}} {{ name | trim }}!", { prefix = "Mr.", name = " John ", }) @@ -54,7 +54,7 @@ describe("registry expressions", function() assert.same( Result.success "Hello, Sir MR. John!", - expr.eval("Hello, {{prefix|to_upper | format 'Sir %s'}} {{ name | trim }}!", { + expr.interpolate("Hello, {{prefix|to_upper | format 'Sir %s'}} {{ name | trim }}!", { prefix = "Mr.", name = " John ", }) @@ -63,20 +63,22 @@ describe("registry expressions", function() it("should reject invalid values", function() assert.is_true( - match.matches [[^.*Value is nil: "non_existent"]](expr.eval("Hello, {{non_existent}}", {}):err_or_nil()) + match.matches [[^.*Value is nil: "non_existent"]]( + expr.interpolate("Hello, {{non_existent}}", {}):err_or_nil() + ) ) end) it("should reject invalid filters", function() assert.is_true( match.matches [[^.*Invalid filter expression: "whut"]]( - expr.eval("Hello, {{ value | whut }}", { value = "value" }):err_or_nil() + expr.interpolate("Hello, {{ value | whut }}", { value = "value" }):err_or_nil() ) ) assert.is_true( match.matches [[^.*Failed to parse filter: "wh%-!uut"]]( - expr.eval("Hello, {{ value | wh-!uut }}", { value = "value" }):err_or_nil() + expr.interpolate("Hello, {{ value | wh-!uut }}", { value = "value" }):err_or_nil() ) ) end) -- cgit v1.2.3-70-g09d2