From dd64edd58fe25ec74ae5958128cf3f74b0692f3b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 28 Jan 2026 18:43:14 +0800 Subject: Fixed compiler issues and added 800+ test cases. --- spec/outputs/test/yaml_string_spec.lua | 42 ++++++++++++++++------------------ 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'spec/outputs/test/yaml_string_spec.lua') 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 @@ return describe("yaml string", function() it("should create basic yaml string", function() local s = "hello\nworld" - assert.is_true(s:match("hello")) - return assert.is_true(s:match("world")) + assert.is_true((s:match("hello") ~= nil)) + return assert.is_true((s:match("world") ~= nil)) end) it("should preserve indentation", function() local s = "key1: value1\nkey2: value2" - assert.is_true(s:match("key1")) - return assert.is_true(s:match("key2")) + assert.is_true((s:match("key1") ~= nil)) + return assert.is_true((s:match("key2") ~= nil)) end) it("should support interpolation", function() local name = "test" @@ -17,22 +17,23 @@ return describe("yaml string", function() it("should handle complex interpolation", function() local x, y = 10, 20 local s = "point:\n\tx: " .. tostring(x) .. "\n\ty: " .. tostring(y) - assert.is_true(s:match("x: 10")) - return assert.is_true(s:match("y: 20")) + assert.is_true((s:match("x: 10") ~= nil)) + return assert.is_true((s:match("y: 20") ~= nil)) end) it("should work with expressions", function() local s = "result: " .. tostring(1 + 2) - return assert.is_true(s:match("result: 3")) + return assert.is_true((s:match("result: 3") ~= nil)) end) it("should support multiline with variables", function() local config = "database:\n\thost: localhost\n\tport: 5432\n\tname: mydb" - assert.is_true(config:match("database:")) - return assert.is_true(config:match("host:")) + assert.is_true((config:match("database:") ~= nil)) + return assert.is_true((config:match("host:") ~= nil)) end) it("should escape special characters", function() + local Hello = "Hello" local s = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" - assert.is_true(s:match("path:")) - return assert.is_true(s:match("note:")) + return assert.same(s, [[path: "C:\Program Files\App" +note: 'He said: "Hello!"']]) end) it("should work in function", function() local fn @@ -41,8 +42,7 @@ return describe("yaml string", function() return str end local result = fn() - assert.is_true(result:match("foo:")) - return assert.is_true(result:match("bar:")) + return assert.same(result, "foo:\n\tbar: baz") end) it("should strip common leading whitespace", function() local fn @@ -51,36 +51,34 @@ return describe("yaml string", function() return s end local result = fn() - assert.is_true(result:match("nested:")) - return assert.is_true(result:match("item:")) + return assert.same(result, "nested:\n item: value") end) it("should support empty lines", function() local s = "line1\nline3" - assert.is_true(s:match("line1")) - return assert.is_true(s:match("line3")) + return assert.same(s, "line1\nline3") end) it("should work with table access in interpolation", function() local t = { value = 100 } local s = "value: " .. tostring(t.value) - return assert.is_true(s:match("value: 100")) + return assert.same(s, "value: 100") end) it("should support function calls in interpolation", function() local s = "result: " .. tostring((function() return 42 end)()) - return assert.is_true(s:match("result: 42")) + return assert.same(s, "result: 42") end) it("should handle quotes correctly", function() local s = "\"quoted\"\n'single quoted'" - assert.is_true(s:match('"quoted"')) - return assert.is_true(s:match("'single quoted'")) + assert.is_true((s:match('"quoted"') ~= nil)) + return assert.is_true((s:match("'single quoted'") ~= nil)) end) it("should work with multiple interpolations", function() local a, b, c = 1, 2, 3 local s = "values: " .. tostring(a) .. ", " .. tostring(b) .. ", " .. tostring(c) - return assert.is_true(s:match("values: 1, 2, 3")) + return assert.same(s, "values: 1, 2, 3") end) return it("should preserve newlines", function() local s = "first line\nsecond line\nthird line" -- cgit v1.2.3-55-g6feb