aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs')
-rw-r--r--spec/outputs/test/break_multiple_values_spec.lua51
-rw-r--r--spec/outputs/test/format_spec.lua8
2 files changed, 56 insertions, 3 deletions
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()
1676 assert.is_nil(x) 1676 assert.is_nil(x)
1677 return assert.is_nil(y) 1677 return assert.is_nil(y)
1678 end) 1678 end)
1679 return it("should mix break continue and value break with value break winning", function() 1679 it("should mix break continue and value break with value break winning", function()
1680 local x, y 1680 local x, y
1681 for i = 1, 9 do 1681 for i = 1, 9 do
1682 if i % 2 == 0 then 1682 if i % 2 == 0 then
@@ -1694,4 +1694,53 @@ return describe("break with multiple values", function()
1694 assert.same(x, 5) 1694 assert.same(x, 5)
1695 return assert.same(y, 15) 1695 return assert.same(y, 15)
1696 end) 1696 end)
1697 it("should allow nesting do and for", function()
1698 local x, y
1699 do
1700 repeat
1701 local min, max = 1, 10
1702 if max > min then
1703 for j = min, max do
1704 if j > 5 then
1705 x, y = j, j * 10
1706 break
1707 end
1708 end
1709 break
1710 end
1711 x, y = 0, 0
1712 break
1713 until true
1714 end
1715 assert.same(x, 6)
1716 return assert.same(y, 60)
1717 end)
1718 return it("should allow nesting do and with", function()
1719 local x
1720 do
1721 local _with_0 = {
1722 a = 123,
1723 b = true
1724 }
1725 repeat
1726 do
1727 if _with_0.b then
1728 local _with_1 = {
1729 a = _with_0.a,
1730 b = _with_0.b,
1731 c = "ok"
1732 }
1733 repeat
1734 if _with_1.b and _with_1.c == "ok" then
1735 x = _with_1.a
1736 break
1737 end
1738 until true
1739 break
1740 end
1741 end
1742 until true
1743 end
1744 return assert.same(x, 123)
1745 end)
1697end) 1746end)
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 = {
113 "spec/inputs/test/loops_spec.yue", 113 "spec/inputs/test/loops_spec.yue",
114 "spec/inputs/test/if_assignment_spec.yue", 114 "spec/inputs/test/if_assignment_spec.yue",
115 "spec/inputs/test/tables_advanced_spec.yue", 115 "spec/inputs/test/tables_advanced_spec.yue",
116 "spec/inputs/test/break_multiple_values_spec.yue",
116 "spec/inputs/unicode/macro_export.yue", 117 "spec/inputs/unicode/macro_export.yue",
117 "spec/inputs/unicode/attrib.yue", 118 "spec/inputs/unicode/attrib.yue",
118 "spec/inputs/unicode/macro.yue", 119 "spec/inputs/unicode/macro.yue",
@@ -182,11 +183,14 @@ return describe("format", function()
182 local f = io.open(file) 183 local f = io.open(file)
183 local code = f:read("a*") 184 local code = f:read("a*")
184 f:close() 185 f:close()
185 local original_ast = yue.to_ast(code) 186 local original_ast, err = yue.to_ast(code)
187 assert.is_nil(err)
186 assert.is_not_nil(original_ast) 188 assert.is_not_nil(original_ast)
187 rewriteLineCol(original_ast) 189 rewriteLineCol(original_ast)
188 local formated = yue.format(code, 0, true) 190 local formated = yue.format(code, 0, true)
189 local ast = yue.to_ast(formated) 191 local ast
192 ast, err = yue.to_ast(formated)
193 assert.is_nil(err)
190 assert.is_not_nil(ast) 194 assert.is_not_nil(ast)
191 rewriteLineCol(ast) 195 rewriteLineCol(ast)
192 return assert.same(original_ast, ast) 196 return assert.same(original_ast, ast)