aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/string_interpolation_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/test/string_interpolation_spec.lua')
-rw-r--r--spec/outputs/test/string_interpolation_spec.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/outputs/test/string_interpolation_spec.lua b/spec/outputs/test/string_interpolation_spec.lua
new file mode 100644
index 0000000..abf23eb
--- /dev/null
+++ b/spec/outputs/test/string_interpolation_spec.lua
@@ -0,0 +1,36 @@
1return describe("string interpolation", function()
2 it("should interpolate in double quotes", function()
3 local name = "World"
4 local result = "Hello " .. tostring(name) .. "!"
5 return assert.same(result, "Hello World!")
6 end)
7 it("should interpolate numbers", function()
8 local a, b = 10, 20
9 local result = tostring(a) .. " + " .. tostring(b) .. " = " .. tostring(a + b)
10 return assert.same(result, "10 + 20 = 30")
11 end)
12 it("should interpolate expressions", function()
13 local x = 5
14 local result = "x * 2 = " .. tostring(x * 2)
15 return assert.same(result, "x * 2 = 10")
16 end)
17 it("should interpolate function calls", function()
18 local result = "result: " .. tostring(math.floor(5.5))
19 return assert.same(result, "result: 5")
20 end)
21 it("should interpolate in string literals", function()
22 local x = 100
23 local result = "Value: " .. tostring(x)
24 return assert.same(result, "Value: 100")
25 end)
26 it("should work with nested interpolation", function()
27 local inner = "inner"
28 local result = "Outer: " .. tostring(inner)
29 return assert.same(result, "Outer: inner")
30 end)
31 return it("should not interpolate in single quotes", function()
32 local name = "World"
33 local result = 'Hello #{name}!'
34 return assert.same(result, 'Hello #{name}!')
35 end)
36end)