From 640dcd82b30629f54596820c09144dfff10cb2c0 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 12 Feb 2026 09:08:12 +0800 Subject: Added more tests. --- spec/outputs/test/break_multiple_values_spec.lua | 51 +++++++++++++++++++++++- spec/outputs/test/format_spec.lua | 8 +++- 2 files changed, 56 insertions(+), 3 deletions(-) (limited to 'spec/outputs/test') diff --git a/spec/outputs/test/break_multiple_values_spec.lua b/spec/outputs/test/break_multiple_values_spec.lua index ba14a64..7a8bc87 100644 --- a/spec/outputs/test/break_multiple_values_spec.lua +++ b/spec/outputs/test/break_multiple_values_spec.lua @@ -1676,7 +1676,7 @@ return describe("break with multiple values", function() assert.is_nil(x) return assert.is_nil(y) end) - return it("should mix break continue and value break with value break winning", function() + it("should mix break continue and value break with value break winning", function() local x, y for i = 1, 9 do if i % 2 == 0 then @@ -1694,4 +1694,53 @@ return describe("break with multiple values", function() assert.same(x, 5) return assert.same(y, 15) end) + it("should allow nesting do and for", function() + local x, y + do + repeat + local min, max = 1, 10 + if max > min then + for j = min, max do + if j > 5 then + x, y = j, j * 10 + break + end + end + break + end + x, y = 0, 0 + break + until true + end + assert.same(x, 6) + return assert.same(y, 60) + end) + return it("should allow nesting do and with", function() + local x + do + local _with_0 = { + a = 123, + b = true + } + repeat + do + if _with_0.b then + local _with_1 = { + a = _with_0.a, + b = _with_0.b, + c = "ok" + } + repeat + if _with_1.b and _with_1.c == "ok" then + x = _with_1.a + break + end + until true + break + end + end + until true + end + return assert.same(x, 123) + end) end) diff --git a/spec/outputs/test/format_spec.lua b/spec/outputs/test/format_spec.lua index 3e98e4a..c9ea3c2 100644 --- a/spec/outputs/test/format_spec.lua +++ b/spec/outputs/test/format_spec.lua @@ -113,6 +113,7 @@ local files = { "spec/inputs/test/loops_spec.yue", "spec/inputs/test/if_assignment_spec.yue", "spec/inputs/test/tables_advanced_spec.yue", + "spec/inputs/test/break_multiple_values_spec.yue", "spec/inputs/unicode/macro_export.yue", "spec/inputs/unicode/attrib.yue", "spec/inputs/unicode/macro.yue", @@ -182,11 +183,14 @@ return describe("format", function() local f = io.open(file) local code = f:read("a*") f:close() - local original_ast = yue.to_ast(code) + local original_ast, err = yue.to_ast(code) + assert.is_nil(err) assert.is_not_nil(original_ast) rewriteLineCol(original_ast) local formated = yue.format(code, 0, true) - local ast = yue.to_ast(formated) + local ast + ast, err = yue.to_ast(formated) + assert.is_nil(err) assert.is_not_nil(ast) rewriteLineCol(ast) return assert.same(original_ast, ast) -- cgit v1.2.3-55-g6feb