Comparison

spec/util_interpolation_spec.lua @ 10352:dc1e6c2fb50a

util.interpolation: Test map syntax
author Kim Alvefur <zash@zash.se>
date Sun, 20 Oct 2019 20:58:19 +0200
parent 10351:72b23c5f74fb
child 10412:b788b5257945
comparison
equal deleted inserted replaced
10351:72b23c5f74fb 10352:dc1e6c2fb50a
15 }]] 15 }]]
16 local expect_array = [[ 16 local expect_array = [[
17 1. HELLO 17 1. HELLO
18 2. WORLD 18 2. WORLD
19 ]] 19 ]]
20 local template_map = [[
21 {foo%{idx}: {item!}
22 }]]
23 local expect_map = [[
24 FOO: bar
25 ]]
20 26
21 describe("util.interpolation", function () 27 describe("util.interpolation", function ()
22 it("renders", function () 28 it("renders", function ()
23 local render = require "util.interpolation".new("%b{}", string.upper); 29 local render = require "util.interpolation".new("%b{}", string.upper);
24 assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); 30 assert.equal(expect1, render(template, { greet = "Hello", name = "world" }));
25 assert.equal(expect2, render(template, { greet = "Hello" })); 31 assert.equal(expect2, render(template, { greet = "Hello" }));
26 assert.equal(expect3, render(template, { name = "you" })); 32 assert.equal(expect3, render(template, { name = "you" }));
27 assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); 33 assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } }));
34 assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } }));
28 end); 35 end);
29 end); 36 end);