Comparison

spec/util_interpolation_spec.lua @ 11065:95eb1a981ef6

util.interpolation: Add test for ~ when value is false (not just nil)
author Matthew Wild <mwild1@gmail.com>
date Wed, 09 Sep 2020 17:12:00 +0100
parent 11064:af1e3b7d9ea3
child 11308:5d4d90d1eabb
comparison
equal deleted inserted replaced
11064:af1e3b7d9ea3 11065:95eb1a981ef6
31 }]] 31 }]]
32 local expect_map = [[ 32 local expect_map = [[
33 FOO: bar 33 FOO: bar
34 ]] 34 ]]
35 local template_not = [[ 35 local template_not = [[
36 {thing~Thing is nil}{thing&Thing is not nil} 36 {thing~Thing is falsy}{thing&Thing is truthy}
37 ]] 37 ]]
38 local expect_not_true = [[ 38 local expect_not_true = [[
39 Thing is not nil 39 Thing is truthy
40 ]] 40 ]]
41 local expect_not_nil = [[ 41 local expect_not_nil = [[
42 Thing is nil 42 Thing is falsy
43 ]]
44 local expect_not_false = [[
45 Thing is falsy
43 ]] 46 ]]
44 describe("util.interpolation", function () 47 describe("util.interpolation", function ()
45 it("renders", function () 48 it("renders", function ()
46 local render = require "util.interpolation".new("%b{}", string.upper, { sort = function (t) table.sort(t) return t end }); 49 local render = require "util.interpolation".new("%b{}", string.upper, { sort = function (t) table.sort(t) return t end });
47 assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); 50 assert.equal(expect1, render(template, { greet = "Hello", name = "world" }));
51 assert.equal(expect_func_pipe, render(template_func_pipe, { foo = { "c", "a", "d", "b", } })); 54 assert.equal(expect_func_pipe, render(template_func_pipe, { foo = { "c", "a", "d", "b", } }));
52 -- assert.equal("", render(template_func_pipe, { foo = nil })); -- FIXME 55 -- assert.equal("", render(template_func_pipe, { foo = nil })); -- FIXME
53 assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); 56 assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } }));
54 assert.equal(expect_not_true, render(template_not, { thing = true })); 57 assert.equal(expect_not_true, render(template_not, { thing = true }));
55 assert.equal(expect_not_nil, render(template_not, { thing = nil })); 58 assert.equal(expect_not_nil, render(template_not, { thing = nil }));
59 assert.equal(expect_not_false, render(template_not, { thing = false }));
56 end); 60 end);
57 end); 61 end);