1 | suite 'String Interpolation', ->
|
2 |
|
3 | test 'interpolate one string variable', ->
|
4 | b = 'b'
|
5 | eq 'abc', "a#{b}c"
|
6 |
|
7 | test 'interpolate two string variables', ->
|
8 | b = 'b'
|
9 | c = 'c'
|
10 | eq 'abcd', "a#{b}#{c}d"
|
11 |
|
12 | test 'interpolate one numeric variable in the middle of the string', ->
|
13 | b = 0
|
14 | eq 'a0c', "a#{b}c"
|
15 |
|
16 | test 'interpolate one numeric variable at the start of the string', ->
|
17 | a = 0
|
18 | eq '0bc', "#{a}bc"
|
19 |
|
20 | test 'interpolate one numeric variable at the end of the string', ->
|
21 | c = 0
|
22 | eq 'ab0', "ab#{c}"
|
23 |
|
24 | test 'interpolations always produce a string', ->
|
25 | eq '0', "#{0}"
|
26 | eq 'string', typeof "#{0 + 1}"
|
27 |
|
28 | test 'interpolate a function call', ->
|
29 | b = -> 'b'
|
30 | eq 'abc', "a#{b()}c"
|
31 | eq 'abc', "a#{b 0}c"
|
32 |
|
33 | test 'interpolate a math expression (add)', ->
|
34 | eq 'a5c', "a#{2 + 3}c"
|
35 |
|
36 | test 'interpolate a math expression (subtract)', ->
|
37 | eq 'a2c', "a#{5 - 3}c"
|
38 |
|
39 | test 'interpolate a math expression (multiply)', ->
|
40 | eq 'a6c', "a#{2 * 3}c"
|
41 |
|
42 | test 'interpolate a math expression (divide)', ->
|
43 | eq 'a2c', "a#{4 / 2}c"
|
44 |
|
45 | test 'nested interpolation with double quotes', ->
|
46 | b = 'b'
|
47 | c = 'c'
|
48 | eq 'abcd', "a#{b + "#{c}"}d"
|
49 |
|
50 | test 'nested interpolation with single quotes (should not interpolate)', ->
|
51 | b = 'b'
|
52 | c = 'c'
|
53 | eq 'ab#{c}d', "a#{b + '#{c}'}d"
|
54 |
|
55 | test 'multiline interpolation', ->
|
56 | b = 'b'
|
57 |
|
58 | eq "a
|
59 | b
|
60 | c
|
61 | ", "a
|
62 | #{b}
|
63 | c
|
64 | "
|
65 | eq """
|
66 | a
|
67 | b
|
68 | c
|
69 | """, """
|
70 | a
|
71 | #{b}
|
72 | c
|
73 | """
|