aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/yaml_string_spec.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-27 00:30:56 +0000
committerLi Jin <dragon-fly@qq.com>2026-01-27 00:30:56 +0000
commit7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (patch)
treeceba95c48bd8d5d9fff3d1206483ddf073c0e03d /spec/outputs/test/yaml_string_spec.lua
parente70e63a9737ed3a9e72f1329901075498190e6b4 (diff)
downloadyuescript-compiler-improvements.tar.gz
yuescript-compiler-improvements.tar.bz2
yuescript-compiler-improvements.zip
Add compiler improvements and comprehensive test suitecompiler-improvements
- Fixed path option handling to avoid semicolon concatenation issues - Added exception handling for std::length_error and general exceptions - Added comprehensive test specifications for advanced language features Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'spec/outputs/test/yaml_string_spec.lua')
-rw-r--r--spec/outputs/test/yaml_string_spec.lua99
1 files changed, 99 insertions, 0 deletions
diff --git a/spec/outputs/test/yaml_string_spec.lua b/spec/outputs/test/yaml_string_spec.lua
new file mode 100644
index 0000000..258ab92
--- /dev/null
+++ b/spec/outputs/test/yaml_string_spec.lua
@@ -0,0 +1,99 @@
1return describe("yaml string", function()
2 it("should create basic yaml string", function()
3 local s = "hello\nworld"
4 assert.is_true(s:match("hello"))
5 return assert.is_true(s:match("world"))
6 end)
7 it("should preserve indentation", function()
8 local s = "key1: value1\nkey2: value2"
9 assert.is_true(s:match("key1"))
10 return assert.is_true(s:match("key2"))
11 end)
12 it("should support interpolation", function()
13 local name = "test"
14 local s = "hello " .. tostring(name)
15 return assert.same(s, "hello test")
16 end)
17 it("should handle complex interpolation", function()
18 local x, y = 10, 20
19 local s = "point:\n\tx: " .. tostring(x) .. "\n\ty: " .. tostring(y)
20 assert.is_true(s:match("x: 10"))
21 return assert.is_true(s:match("y: 20"))
22 end)
23 it("should work with expressions", function()
24 local s = "result: " .. tostring(1 + 2)
25 return assert.is_true(s:match("result: 3"))
26 end)
27 it("should support multiline with variables", function()
28 local config = "database:\n\thost: localhost\n\tport: 5432\n\tname: mydb"
29 assert.is_true(config:match("database:"))
30 return assert.is_true(config:match("host:"))
31 end)
32 it("should escape special characters", function()
33 local s = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
34 assert.is_true(s:match("path:"))
35 return assert.is_true(s:match("note:"))
36 end)
37 it("should work in function", function()
38 local fn
39 fn = function()
40 local str = "foo:\n\tbar: baz"
41 return str
42 end
43 local result = fn()
44 assert.is_true(result:match("foo:"))
45 return assert.is_true(result:match("bar:"))
46 end)
47 it("should strip common leading whitespace", function()
48 local fn
49 fn = function()
50 local s = "nested:\n\titem: value"
51 return s
52 end
53 local result = fn()
54 assert.is_true(result:match("nested:"))
55 return assert.is_true(result:match("item:"))
56 end)
57 it("should support empty lines", function()
58 local s = "line1\nline3"
59 assert.is_true(s:match("line1"))
60 return assert.is_true(s:match("line3"))
61 end)
62 it("should work with table access in interpolation", function()
63 local t = {
64 value = 100
65 }
66 local s = "value: " .. tostring(t.value)
67 return assert.is_true(s:match("value: 100"))
68 end)
69 it("should support function calls in interpolation", function()
70 local s = "result: " .. tostring((function()
71 return 42
72 end)())
73 return assert.is_true(s:match("result: 42"))
74 end)
75 it("should handle quotes correctly", function()
76 local s = "\"quoted\"\n'single quoted'"
77 assert.is_true(s:match('"quoted"'))
78 return assert.is_true(s:match("'single quoted'"))
79 end)
80 it("should work with multiple interpolations", function()
81 local a, b, c = 1, 2, 3
82 local s = "values: " .. tostring(a) .. ", " .. tostring(b) .. ", " .. tostring(c)
83 return assert.is_true(s:match("values: 1, 2, 3"))
84 end)
85 return it("should preserve newlines", function()
86 local s = "first line\nsecond line\nthird line"
87 local lines
88 do
89 local _accum_0 = { }
90 local _len_0 = 1
91 for line in s:gmatch("[^\n]+") do
92 _accum_0[_len_0] = line
93 _len_0 = _len_0 + 1
94 end
95 lines = _accum_0
96 end
97 return assert.same(#lines, 3)
98 end)
99end)