aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/5.1/test/string_spec.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-26 17:45:26 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-26 17:45:56 +0800
commite02321107277a63e7dcb12ab163c9942ac101b87 (patch)
treef38c6f2fbf4ee35df4938933dbc1e645733356f4 /spec/outputs/5.1/test/string_spec.lua
parent5d5b657f606b5939062983b1f90c3359d542672e (diff)
downloadyuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.gz
yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.bz2
yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.zip
Updated tests.
Diffstat (limited to 'spec/outputs/5.1/test/string_spec.lua')
-rw-r--r--spec/outputs/5.1/test/string_spec.lua138
1 files changed, 0 insertions, 138 deletions
diff --git a/spec/outputs/5.1/test/string_spec.lua b/spec/outputs/5.1/test/string_spec.lua
deleted file mode 100644
index 95eb470..0000000
--- a/spec/outputs/5.1/test/string_spec.lua
+++ /dev/null
@@ -1,138 +0,0 @@
1return describe("string", function() -- 1
2 it("should support single quote strings", function() -- 2
3 local s = 'hello' -- 3
4 return assert.same(s, "hello") -- 4
5 end) -- 2
6 it("should support double quote strings", function() -- 6
7 local s = "world" -- 7
8 return assert.same(s, "world") -- 8
9 end) -- 6
10 it("should support escape sequences", function() -- 10
11 local s = "hello\nworld" -- 11
12 return assert.is_true(s:match("\n") ~= nil) -- 12
13 end) -- 10
14 it("should support escaped quotes", function() -- 14
15 local s = "he said \"hello\"" -- 15
16 return assert.same(s, 'he said "hello"') -- 16
17 end) -- 14
18 it("should support backslash escape", function() -- 18
19 local s = "\\" -- 19
20 return assert.same(s, "\\") -- 20
21 end) -- 18
22 it("should support multi-line strings with [[ ]]", function() -- 22
23 local s = [[ hello
24 world
25 ]] -- 23
26 assert.is_true(s:match("hello") ~= nil) -- 27
27 return assert.is_true(s:match("world") ~= nil) -- 28
28 end) -- 22
29 it("should support multi-line strings with [=[ ]=]", function() -- 30
30 local s = [==[ hello
31 world
32 ]==] -- 31
33 assert.is_true(s:match("hello") ~= nil) -- 35
34 return assert.is_true(s:match("world") ~= nil) -- 36
35 end) -- 30
36 it("should support string interpolation with double quotes", function() -- 38
37 local name = "world" -- 39
38 local s = "hello " .. tostring(name) -- 40
39 return assert.same(s, "hello world") -- 41
40 end) -- 38
41 it("should support expression interpolation", function() -- 43
42 local a, b = 1, 2 -- 44
43 local s = tostring(a) .. " + " .. tostring(b) .. " = " .. tostring(a + b) -- 45
44 return assert.same(s, "1 + 2 = 3") -- 46
45 end) -- 43
46 it("should not interpolate in single quotes", function() -- 48
47 local name = "world" -- 49
48 local s = 'hello #{name}' -- 50
49 return assert.same(s, "hello " .. tostring(name)) -- 51
50 end) -- 48
51 it("should escape interpolation with \#", function() -- 53
52 local name = "world" -- 54
53 local s = "hello \\" .. tostring(name) -- 55
54 return assert.same(s, "hello " .. tostring(name)) -- 56
55 end) -- 53
56 it("should support method calls on string literals", function() -- 58
57 local result = ("hello"):upper() -- 59
58 return assert.same(result, "HELLO") -- 60
59 end) -- 58
60 it("should support chained method calls", function() -- 62
61 local result = ("hello world"):upper():match("HELLO") -- 63
62 return assert.same(result, "HELLO") -- 64
63 end) -- 62
64 it("should support YAML style strings", function() -- 66
65 local s = "hello\nworld" -- 67
66 assert.is_true(s:match("hello") ~= nil) -- 70
67 return assert.is_true(s:match("world") ~= nil) -- 71
68 end) -- 66
69 it("should support YAML style with interpolation", function() -- 73
70 local name = "test" -- 74
71 local s = "hello " .. tostring(name) -- 75
72 return assert.same(s, "hello test\n") -- 77
73 end) -- 73
74 it("should support string concatenation", function() -- 79
75 local s = "hello" .. " " .. "world" -- 80
76 return assert.same(s, "hello world") -- 81
77 end) -- 79
78 it("should handle empty strings", function() -- 83
79 local s = "" -- 84
80 return assert.same(s, "") -- 85
81 end) -- 83
82 it("should support Unicode characters", function() -- 87
83 local s = "hello 世界" -- 88
84 return assert.is_true(s:match("世界") ~= nil) -- 89
85 end) -- 87
86 it("should support string length", function() -- 91
87 local s = "hello" -- 92
88 return assert.same(#s, 5) -- 93
89 end) -- 91
90 it("should support multi-line YAML with complex content", function() -- 95
91 local config = "key1: value1\nkey2: value2\nkey3: value3" -- 96
92 return assert.is_true(config:match("key1") ~= nil) -- 100
93 end) -- 95
94 it("should support interpolation in YAML strings", function() -- 102
95 local x, y = 10, 20 -- 103
96 local s = "point:\n\tx: " .. tostring(x) .. "\n\ty: " .. tostring(y) -- 104
97 assert.is_true(s:match("x: 10") ~= nil) -- 108
98 return assert.is_true(s:match("y: 20") ~= nil) -- 109
99 end) -- 102
100 it("should support function call in interpolation", function() -- 111
101 local s = "result: " .. tostring(function() -- 112
102 return 42 -- 112
103 end) -- 112
104 return assert.same(s, "result: 42") -- 113
105 end) -- 111
106 it("should support table indexing in interpolation", function() -- 115
107 local t = { -- 116
108 value = 100 -- 116
109 } -- 116
110 local s = "value: " .. tostring(t.value) -- 117
111 return assert.same(s, "value: 100") -- 118
112 end) -- 115
113 it("should handle escaped characters correctly", function() -- 120
114 local s = "tab:\t, newline:\n, return:\r" -- 121
115 assert.is_true(s:match("\t") ~= nil) -- 122
116 return assert.is_true(s:match("\n") ~= nil) -- 123
117 end) -- 120
118 it("should support string methods with colon syntax", function() -- 125
119 local s = "hello" -- 126
120 return assert.same(s:sub(1, 2), "he") -- 127
121 end) -- 125
122 it("should work in expressions", function() -- 129
123 local result = "hello" .. " world" -- 130
124 return assert.same(result, "hello world") -- 131
125 end) -- 129
126 it("should support octal escape", function() -- 133
127 local s = "\65" -- 134
128 return assert.same(s, "A") -- 135
129 end) -- 133
130 it("should support hex escape", function() -- 137
131 local s = "\x41" -- 138
132 return assert.same(s, "A") -- 139
133 end) -- 137
134 return it("should support unicode escape", function() -- 141
135 local s = "\u{4e16}" -- 142
136 return assert.same(s, "世") -- 143
137 end) -- 141
138end) -- 1