aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/string_interpolation_spec.yue
blob: 02b160614b5678a1767462d64f78c3b36582e0ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
describe "string interpolation", ->
	it "should interpolate in double quotes", ->
		name = "World"
		result = "Hello #{name}!"
		assert.same result, "Hello World!"

	it "should interpolate numbers", ->
		a, b = 10, 20
		result = "#{a} + #{b} = #{a + b}"
		assert.same result, "10 + 20 = 30"

	it "should interpolate expressions", ->
		x = 5
		result = "x * 2 = #{x * 2}"
		assert.same result, "x * 2 = 10"

	it "should interpolate function calls", ->
		result = "result: #{math.floor 5.5}"
		assert.same result, "result: 5"

	it "should interpolate in string literals", ->
		x = 100
		result = "Value: #{x}"
		assert.same result, "Value: 100"

	it "should work with nested interpolation", ->
		inner = "inner"
		result = "Outer: #{inner}"
		assert.same result, "Outer: inner"

	it "should not interpolate in single quotes", ->
		name = "World"
		result = 'Hello #{name}!'
		assert.same result, 'Hello #{name}!'