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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
describe "string", ->
it "should support single quote strings", ->
s = 'hello'
assert.same s, "hello"
it "should support double quote strings", ->
s = "world"
assert.same s, "world"
it "should support escape sequences", ->
s = "hello\nworld"
assert.is_true s\match("\n") ~= nil
it "should support escaped quotes", ->
s = "he said \"hello\""
assert.same s, 'he said "hello"'
it "should support backslash escape", ->
s = "\\"
assert.same s, "\\"
it "should support multi-line strings with [[ ]]", ->
s = [[
hello
world
]]
assert.is_true s\match("hello") ~= nil
assert.is_true s\match("world") ~= nil
it "should support multi-line strings with [=[ ]=]", ->
s = [==[
hello
world
]==]
assert.is_true s\match("hello") ~= nil
assert.is_true s\match("world") ~= nil
it "should support string interpolation with double quotes", ->
name = "world"
s = "hello #{name}"
assert.same s, "hello world"
it "should support expression interpolation", ->
a, b = 1, 2
s = "#{a} + #{b} = #{a + b}"
assert.same s, "1 + 2 = 3"
it "should not interpolate in single quotes", ->
name = "world"
s = 'hello #{name}'
assert.same s, "hello \#{name}"
it "should escape interpolation with \\\#", ->
name = "world"
s = "hello \#{name}"
assert.same s, 'hello #{name}'
it "should support method calls on string literals", ->
result = "hello"\upper!
assert.same result, "HELLO"
it "should support chained method calls", ->
result = "hello world"\upper!\match "HELLO"
assert.same result, "HELLO"
it "should support YAML style strings", ->
s = |
hello
world
assert.is_true s\match("hello") ~= nil
assert.is_true s\match("world") ~= nil
it "should support YAML style with interpolation", ->
name = "test"
s = |
hello #{name}
assert.same s, "hello test"
it "should support string concatenation", ->
s = "hello" .. " " .. "world"
assert.same s, "hello world"
it "should handle empty strings", ->
s = ""
assert.same s, ""
it "should support Unicode characters", ->
s = "hello 世界"
assert.is_true s\match("世界") ~= nil
it "should support string length", ->
s = "hello"
assert.same #s, 5
it "should support multi-line YAML with complex content", ->
config = |
key1: value1
key2: value2
key3: value3
assert.is_true config\match("key1") ~= nil
it "should support interpolation in YAML strings", ->
x, y = 10, 20
s = |
point:
x: #{x}
y: #{y}
assert.is_true s\match("x: 10") ~= nil
assert.is_true s\match("y: 20") ~= nil
it "should support function call in interpolation", ->
s = "result: #{(-> 42)!}"
assert.same s, "result: 42"
it "should support table indexing in interpolation", ->
t = {value: 100}
s = "value: #{t.value}"
assert.same s, "value: 100"
it "should handle escaped characters correctly", ->
s = "tab:\t, newline:\n, return:\r"
assert.is_true s\match("\t") ~= nil
assert.is_true s\match("\n") ~= nil
it "should support string methods with colon syntax", ->
s = "hello"
assert.same s\sub(1, 2), "he"
it "should work in expressions", ->
result = "hello" .. " world"
assert.same result, "hello world"
it "should support octal escape", ->
s = "\65"
assert.same s, "A"
it "should support hex escape", ->
s = "\x41"
assert.same s, "A"
it "should support unicode escape", ->
s = "\u{4e16}"
assert.same s, "世"
|