aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/yaml_string_spec.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
commitdd64edd58fe25ec74ae5958128cf3f74b0692f3b (patch)
tree0f2de1df55897e2713977c5a53936757e14b477a /spec/outputs/test/yaml_string_spec.lua
parent7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (diff)
downloadyuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.gz
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.bz2
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.zip
Fixed compiler issues and added 800+ test cases.
Diffstat (limited to 'spec/outputs/test/yaml_string_spec.lua')
-rw-r--r--spec/outputs/test/yaml_string_spec.lua42
1 files changed, 20 insertions, 22 deletions
diff --git a/spec/outputs/test/yaml_string_spec.lua b/spec/outputs/test/yaml_string_spec.lua
index 258ab92..e95ab55 100644
--- a/spec/outputs/test/yaml_string_spec.lua
+++ b/spec/outputs/test/yaml_string_spec.lua
@@ -1,13 +1,13 @@
1return describe("yaml string", function() 1return describe("yaml string", function()
2 it("should create basic yaml string", function() 2 it("should create basic yaml string", function()
3 local s = "hello\nworld" 3 local s = "hello\nworld"
4 assert.is_true(s:match("hello")) 4 assert.is_true((s:match("hello") ~= nil))
5 return assert.is_true(s:match("world")) 5 return assert.is_true((s:match("world") ~= nil))
6 end) 6 end)
7 it("should preserve indentation", function() 7 it("should preserve indentation", function()
8 local s = "key1: value1\nkey2: value2" 8 local s = "key1: value1\nkey2: value2"
9 assert.is_true(s:match("key1")) 9 assert.is_true((s:match("key1") ~= nil))
10 return assert.is_true(s:match("key2")) 10 return assert.is_true((s:match("key2") ~= nil))
11 end) 11 end)
12 it("should support interpolation", function() 12 it("should support interpolation", function()
13 local name = "test" 13 local name = "test"
@@ -17,22 +17,23 @@ return describe("yaml string", function()
17 it("should handle complex interpolation", function() 17 it("should handle complex interpolation", function()
18 local x, y = 10, 20 18 local x, y = 10, 20
19 local s = "point:\n\tx: " .. tostring(x) .. "\n\ty: " .. tostring(y) 19 local s = "point:\n\tx: " .. tostring(x) .. "\n\ty: " .. tostring(y)
20 assert.is_true(s:match("x: 10")) 20 assert.is_true((s:match("x: 10") ~= nil))
21 return assert.is_true(s:match("y: 20")) 21 return assert.is_true((s:match("y: 20") ~= nil))
22 end) 22 end)
23 it("should work with expressions", function() 23 it("should work with expressions", function()
24 local s = "result: " .. tostring(1 + 2) 24 local s = "result: " .. tostring(1 + 2)
25 return assert.is_true(s:match("result: 3")) 25 return assert.is_true((s:match("result: 3") ~= nil))
26 end) 26 end)
27 it("should support multiline with variables", function() 27 it("should support multiline with variables", function()
28 local config = "database:\n\thost: localhost\n\tport: 5432\n\tname: mydb" 28 local config = "database:\n\thost: localhost\n\tport: 5432\n\tname: mydb"
29 assert.is_true(config:match("database:")) 29 assert.is_true((config:match("database:") ~= nil))
30 return assert.is_true(config:match("host:")) 30 return assert.is_true((config:match("host:") ~= nil))
31 end) 31 end)
32 it("should escape special characters", function() 32 it("should escape special characters", function()
33 local Hello = "Hello"
33 local s = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" 34 local s = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
34 assert.is_true(s:match("path:")) 35 return assert.same(s, [[path: "C:\Program Files\App"
35 return assert.is_true(s:match("note:")) 36note: 'He said: "Hello!"']])
36 end) 37 end)
37 it("should work in function", function() 38 it("should work in function", function()
38 local fn 39 local fn
@@ -41,8 +42,7 @@ return describe("yaml string", function()
41 return str 42 return str
42 end 43 end
43 local result = fn() 44 local result = fn()
44 assert.is_true(result:match("foo:")) 45 return assert.same(result, "foo:\n\tbar: baz")
45 return assert.is_true(result:match("bar:"))
46 end) 46 end)
47 it("should strip common leading whitespace", function() 47 it("should strip common leading whitespace", function()
48 local fn 48 local fn
@@ -51,36 +51,34 @@ return describe("yaml string", function()
51 return s 51 return s
52 end 52 end
53 local result = fn() 53 local result = fn()
54 assert.is_true(result:match("nested:")) 54 return assert.same(result, "nested:\n item: value")
55 return assert.is_true(result:match("item:"))
56 end) 55 end)
57 it("should support empty lines", function() 56 it("should support empty lines", function()
58 local s = "line1\nline3" 57 local s = "line1\nline3"
59 assert.is_true(s:match("line1")) 58 return assert.same(s, "line1\nline3")
60 return assert.is_true(s:match("line3"))
61 end) 59 end)
62 it("should work with table access in interpolation", function() 60 it("should work with table access in interpolation", function()
63 local t = { 61 local t = {
64 value = 100 62 value = 100
65 } 63 }
66 local s = "value: " .. tostring(t.value) 64 local s = "value: " .. tostring(t.value)
67 return assert.is_true(s:match("value: 100")) 65 return assert.same(s, "value: 100")
68 end) 66 end)
69 it("should support function calls in interpolation", function() 67 it("should support function calls in interpolation", function()
70 local s = "result: " .. tostring((function() 68 local s = "result: " .. tostring((function()
71 return 42 69 return 42
72 end)()) 70 end)())
73 return assert.is_true(s:match("result: 42")) 71 return assert.same(s, "result: 42")
74 end) 72 end)
75 it("should handle quotes correctly", function() 73 it("should handle quotes correctly", function()
76 local s = "\"quoted\"\n'single quoted'" 74 local s = "\"quoted\"\n'single quoted'"
77 assert.is_true(s:match('"quoted"')) 75 assert.is_true((s:match('"quoted"') ~= nil))
78 return assert.is_true(s:match("'single quoted'")) 76 return assert.is_true((s:match("'single quoted'") ~= nil))
79 end) 77 end)
80 it("should work with multiple interpolations", function() 78 it("should work with multiple interpolations", function()
81 local a, b, c = 1, 2, 3 79 local a, b, c = 1, 2, 3
82 local s = "values: " .. tostring(a) .. ", " .. tostring(b) .. ", " .. tostring(c) 80 local s = "values: " .. tostring(a) .. ", " .. tostring(b) .. ", " .. tostring(c)
83 return assert.is_true(s:match("values: 1, 2, 3")) 81 return assert.same(s, "values: 1, 2, 3")
84 end) 82 end)
85 return it("should preserve newlines", function() 83 return it("should preserve newlines", function()
86 local s = "first line\nsecond line\nthird line" 84 local s = "first line\nsecond line\nthird line"