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/inputs/test/string_interpolation_spec.yue | |
| parent | 220a10d0df3341b2bbb0beaee4f90d6480e7ae38 (diff) | |
| download | yuescript-main.tar.gz yuescript-main.tar.bz2 yuescript-main.zip | |
Diffstat (limited to '')
| -rw-r--r-- | spec/inputs/test/string_interpolation_spec.yue | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/inputs/test/string_interpolation_spec.yue b/spec/inputs/test/string_interpolation_spec.yue new file mode 100644 index 0000000..02b1606 --- /dev/null +++ b/spec/inputs/test/string_interpolation_spec.yue | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | describe "string interpolation", -> | ||
| 2 | it "should interpolate in double quotes", -> | ||
| 3 | name = "World" | ||
| 4 | result = "Hello #{name}!" | ||
| 5 | assert.same result, "Hello World!" | ||
| 6 | |||
| 7 | it "should interpolate numbers", -> | ||
| 8 | a, b = 10, 20 | ||
| 9 | result = "#{a} + #{b} = #{a + b}" | ||
| 10 | assert.same result, "10 + 20 = 30" | ||
| 11 | |||
| 12 | it "should interpolate expressions", -> | ||
| 13 | x = 5 | ||
| 14 | result = "x * 2 = #{x * 2}" | ||
| 15 | assert.same result, "x * 2 = 10" | ||
| 16 | |||
| 17 | it "should interpolate function calls", -> | ||
| 18 | result = "result: #{math.floor 5.5}" | ||
| 19 | assert.same result, "result: 5" | ||
| 20 | |||
| 21 | it "should interpolate in string literals", -> | ||
| 22 | x = 100 | ||
| 23 | result = "Value: #{x}" | ||
| 24 | assert.same result, "Value: 100" | ||
| 25 | |||
| 26 | it "should work with nested interpolation", -> | ||
| 27 | inner = "inner" | ||
| 28 | result = "Outer: #{inner}" | ||
| 29 | assert.same result, "Outer: inner" | ||
| 30 | |||
| 31 | it "should not interpolate in single quotes", -> | ||
| 32 | name = "World" | ||
| 33 | result = 'Hello #{name}!' | ||
| 34 | assert.same result, 'Hello #{name}!' | ||
