From 15d5dffa63b71c75bcba23046ac20e4a7f0e3a58 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 10 Mar 2018 19:58:41 +0100 Subject: spec: Stub tests for util.interpolation --- spec/util_interpolation_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spec/util_interpolation_spec.lua (limited to 'spec/util_interpolation_spec.lua') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua new file mode 100644 index 00000000..88d9f844 --- /dev/null +++ b/spec/util_interpolation_spec.lua @@ -0,0 +1,17 @@ +local template = [[ +{greet!}, {name?world}! +]]; +local expect1 = [[ +Hello, WORLD! +]]; +local expect2 = [[ +Hello, world! +]]; + +describe("util.interpolation", function () + it("renders", function () + local render = require "util.interpolation".new("%b{}", string.upper); + assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); + assert.equal(expect2, render(template, { greet = "Hello" })); + end); +end); -- cgit v1.2.3 From 8b19b4435f6feded2bfffa4ee5a11716579ec7ea Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 20 Oct 2019 20:53:41 +0200 Subject: util.interpolation: Test #1452 --- spec/util_interpolation_spec.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'spec/util_interpolation_spec.lua') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 88d9f844..9fcad469 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -1,5 +1,5 @@ local template = [[ -{greet!}, {name?world}! +{greet!?Hi}, {name?world}! ]]; local expect1 = [[ Hello, WORLD! @@ -7,11 +7,15 @@ Hello, WORLD! local expect2 = [[ Hello, world! ]]; +local expect3 = [[ +Hi, YOU! +]]; describe("util.interpolation", function () it("renders", function () local render = require "util.interpolation".new("%b{}", string.upper); assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); assert.equal(expect2, render(template, { greet = "Hello" })); + assert.equal(expect3, render(template, { name = "you" })); end); end); -- cgit v1.2.3 From c0a72783661d8008519a0283ac7f107661f89c6b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 20 Oct 2019 20:56:29 +0200 Subject: util.interpolation: Test array syntax --- spec/util_interpolation_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/util_interpolation_spec.lua') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 9fcad469..4106e10b 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -10,6 +10,13 @@ Hello, world! local expect3 = [[ Hi, YOU! ]]; +local template_array = [[ +{foo#{idx}. {item} +}]] +local expect_array = [[ +1. HELLO +2. WORLD +]] describe("util.interpolation", function () it("renders", function () @@ -17,5 +24,6 @@ describe("util.interpolation", function () assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); assert.equal(expect2, render(template, { greet = "Hello" })); assert.equal(expect3, render(template, { name = "you" })); + assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); end); end); -- cgit v1.2.3 From 9889cb8bb4c614939a4a82624b0e7e3539b80b63 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 20 Oct 2019 20:58:19 +0200 Subject: util.interpolation: Test map syntax --- spec/util_interpolation_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/util_interpolation_spec.lua') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 4106e10b..eb49e53b 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -17,6 +17,12 @@ local expect_array = [[ 1. HELLO 2. WORLD ]] +local template_map = [[ +{foo%{idx}: {item!} +}]] +local expect_map = [[ +FOO: bar +]] describe("util.interpolation", function () it("renders", function () @@ -25,5 +31,6 @@ describe("util.interpolation", function () assert.equal(expect2, render(template, { greet = "Hello" })); assert.equal(expect3, render(template, { name = "you" })); assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); + assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); end); end); -- cgit v1.2.3 From e0e0b24f003bcebc564fcebeb745717a4e08b5b7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 17 Nov 2019 15:06:22 +0100 Subject: util.interpolation: Test template filters --- spec/util_interpolation_spec.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'spec/util_interpolation_spec.lua') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index eb49e53b..21d1abe0 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -17,6 +17,15 @@ local expect_array = [[ 1. HELLO 2. WORLD ]] +local template_func_pipe = [[ +{foo|sort#{idx}. {item} +}]] +local expect_func_pipe = [[ +1. A +2. B +3. C +4. D +]] local template_map = [[ {foo%{idx}: {item!} }]] @@ -26,11 +35,12 @@ FOO: bar describe("util.interpolation", function () it("renders", function () - local render = require "util.interpolation".new("%b{}", string.upper); + local render = require "util.interpolation".new("%b{}", string.upper, { sort = function (t) table.sort(t) return t end }); assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); assert.equal(expect2, render(template, { greet = "Hello" })); assert.equal(expect3, render(template, { name = "you" })); assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); + assert.equal(expect_func_pipe, render(template_func_pipe, { foo = { "c", "a", "d", "b", } })); assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); end); end); -- cgit v1.2.3 From a7579e93f5833154aef8d67f068064d71b5dc731 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 17 Nov 2019 15:32:28 +0100 Subject: util.interpolation: Add commented test case for passing nil to filter --- spec/util_interpolation_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/util_interpolation_spec.lua') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 21d1abe0..76000d94 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -41,6 +41,7 @@ describe("util.interpolation", function () assert.equal(expect3, render(template, { name = "you" })); assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); assert.equal(expect_func_pipe, render(template_func_pipe, { foo = { "c", "a", "d", "b", } })); + -- assert.equal("", render(template_func_pipe, { foo = nil })); -- FIXME assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); end); end); -- cgit v1.2.3