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
|
return describe("string", function()
it("should support single quote strings", function()
local s = 'hello'
return assert.same(s, "hello")
end)
it("should support double quote strings", function()
local s = "world"
return assert.same(s, "world")
end)
it("should support escape sequences", function()
local s = "hello\nworld"
return assert.is_true(s:match("\n") ~= nil)
end)
it("should support escaped quotes", function()
local s = "he said \"hello\""
return assert.same(s, 'he said "hello"')
end)
it("should support backslash escape", function()
local s = "\\"
return assert.same(s, "\\")
end)
it("should support multi-line strings with [[ ]]", function()
local s = [[ hello
world
]]
assert.is_true(s:match("hello") ~= nil)
return assert.is_true(s:match("world") ~= nil)
end)
it("should support multi-line strings with [=[ ]=]", function()
local s = [==[ hello
world
]==]
assert.is_true(s:match("hello") ~= nil)
return assert.is_true(s:match("world") ~= nil)
end)
it("should support string interpolation with double quotes", function()
local name = "world"
local s = "hello " .. tostring(name)
return assert.same(s, "hello world")
end)
it("should support expression interpolation", function()
local a, b = 1, 2
local s = tostring(a) .. " + " .. tostring(b) .. " = " .. tostring(a + b)
return assert.same(s, "1 + 2 = 3")
end)
it("should not interpolate in single quotes", function()
local name = "world"
local s = 'hello #{name}'
return assert.same(s, "hello #{name}")
end)
it("should escape interpolation with \\#", function()
local name = "world"
local s = "hello #{name}"
return assert.same(s, 'hello #{name}')
end)
it("should support method calls on string literals", function()
local result = ("hello"):upper()
return assert.same(result, "HELLO")
end)
it("should support chained method calls", function()
local result = ("hello world"):upper():match("HELLO")
return assert.same(result, "HELLO")
end)
it("should support YAML style strings", function()
local s = "hello\nworld"
assert.is_true(s:match("hello") ~= nil)
return assert.is_true(s:match("world") ~= nil)
end)
it("should support YAML style with interpolation", function()
local name = "test"
local s = "hello " .. tostring(name)
return assert.same(s, "hello test")
end)
it("should support string concatenation", function()
local s = "hello" .. " " .. "world"
return assert.same(s, "hello world")
end)
it("should handle empty strings", function()
local s = ""
return assert.same(s, "")
end)
it("should support Unicode characters", function()
local s = "hello 世界"
return assert.is_true(s:match("世界") ~= nil)
end)
it("should support string length", function()
local s = "hello"
return assert.same(#s, 5)
end)
it("should support multi-line YAML with complex content", function()
local config = "key1: value1\nkey2: value2\nkey3: value3"
return assert.is_true(config:match("key1") ~= nil)
end)
it("should support interpolation in YAML strings", function()
local x, y = 10, 20
local s = "point:\n\tx: " .. tostring(x) .. "\n\ty: " .. tostring(y)
assert.is_true(s:match("x: 10") ~= nil)
return assert.is_true(s:match("y: 20") ~= nil)
end)
it("should support function call in interpolation", function()
local s = "result: " .. tostring((function()
return 42
end)())
return assert.same(s, "result: 42")
end)
it("should support table indexing in interpolation", function()
local t = {
value = 100
}
local s = "value: " .. tostring(t.value)
return assert.same(s, "value: 100")
end)
it("should handle escaped characters correctly", function()
local s = "tab:\t, newline:\n, return:\r"
assert.is_true(s:match("\t") ~= nil)
return assert.is_true(s:match("\n") ~= nil)
end)
it("should support string methods with colon syntax", function()
local s = "hello"
return assert.same(s:sub(1, 2), "he")
end)
it("should work in expressions", function()
local result = "hello" .. " world"
return assert.same(result, "hello world")
end)
it("should support octal escape", function()
local s = "\65"
return assert.same(s, "A")
end)
it("should support hex escape", function()
local s = "\x41"
return assert.same(s, "A")
end)
return it("should support unicode escape", function()
local s = "\u{4e16}"
return assert.same(s, "世")
end)
end)
|