diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-30 18:16:45 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-30 18:16:45 +0800 |
| commit | 8c3d786157ec7fef3072feac55c2d5450800568b (patch) | |
| tree | 6c44a85e02abe74e6c3ccc4d7393ba8784c49ce7 /spec/outputs/test/string_interpolation_spec.lua | |
| parent | 220a10d0df3341b2bbb0beaee4f90d6480e7ae38 (diff) | |
| download | yuescript-main.tar.gz yuescript-main.tar.bz2 yuescript-main.zip | |
Diffstat (limited to 'spec/outputs/test/string_interpolation_spec.lua')
| -rw-r--r-- | spec/outputs/test/string_interpolation_spec.lua | 36 |
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 @@ | |||
| 1 | return 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) | ||
| 36 | end) | ||
