aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/test')
-rw-r--r--spec/outputs/test/comprehension_spec.lua31
-rw-r--r--spec/outputs/test/destructure_spec.lua29
-rw-r--r--spec/outputs/test/format_spec.lua14
-rw-r--r--spec/outputs/test/nil_coalescing_spec.lua23
-rw-r--r--spec/outputs/test/pipe_spec.lua13
-rw-r--r--spec/outputs/test/try_catch_spec.lua17
6 files changed, 126 insertions, 1 deletions
diff --git a/spec/outputs/test/comprehension_spec.lua b/spec/outputs/test/comprehension_spec.lua
new file mode 100644
index 0000000..a4682d5
--- /dev/null
+++ b/spec/outputs/test/comprehension_spec.lua
@@ -0,0 +1,31 @@
1return describe("comprehension", function()
2 return it("nested with filter", function()
3 local list = {
4 1,
5 2,
6 3
7 }
8 local out
9 do
10 local _accum_0 = { }
11 local _len_0 = 1
12 for _index_0 = 1, #list do
13 local i = list[_index_0]
14 if i % 2 == 1 then
15 for _index_1 = 1, #list do
16 local j = list[_index_1]
17 if j > i then
18 _accum_0[_len_0] = tostring(i) .. "-" .. tostring(j)
19 _len_0 = _len_0 + 1
20 end
21 end
22 end
23 end
24 out = _accum_0
25 end
26 return assert.same(out, {
27 "1-2",
28 "1-3"
29 })
30 end)
31end)
diff --git a/spec/outputs/test/destructure_spec.lua b/spec/outputs/test/destructure_spec.lua
new file mode 100644
index 0000000..4e18b02
--- /dev/null
+++ b/spec/outputs/test/destructure_spec.lua
@@ -0,0 +1,29 @@
1return describe("destructure", function()
2 return it("defaults and nested", function()
3 local t = {
4 a = 1,
5 b = {
6 c = 3
7 },
8 d = nil
9 }
10 local a, c, d, e = t.a, t.b.c, t.b.d, t.e
11 if d == nil then
12 d = 4
13 end
14 if e == nil then
15 e = 5
16 end
17 return assert.same({
18 a,
19 c,
20 d,
21 e
22 }, {
23 1,
24 3,
25 4,
26 5
27 })
28 end)
29end)
diff --git a/spec/outputs/test/format_spec.lua b/spec/outputs/test/format_spec.lua
index 898fa03..74a511d 100644
--- a/spec/outputs/test/format_spec.lua
+++ b/spec/outputs/test/format_spec.lua
@@ -94,7 +94,19 @@ local files = {
94 "spec/inputs/unicode/metatable.yue", 94 "spec/inputs/unicode/metatable.yue",
95 "spec/inputs/unicode/syntax.yue", 95 "spec/inputs/unicode/syntax.yue",
96 "spec/inputs/unicode/global.yue", 96 "spec/inputs/unicode/global.yue",
97 "spec/inputs/unicode/plus.yue" 97 "spec/inputs/unicode/plus.yue",
98 "spec/inputs/pipe_chain_combo.yue",
99 "spec/inputs/destructure_defaults.yue",
100 "spec/inputs/nil_coalesce_precedence.yue",
101 "spec/inputs/comprehension_nested.yue",
102 "spec/inputs/with_scope_shadow.yue",
103 "spec/inputs/export_mixed.yue",
104 "spec/inputs/unicode/pipe_chain_combo.yue",
105 "spec/inputs/test/destructure_spec.yue",
106 "spec/inputs/test/nil_coalescing_spec.yue",
107 "spec/inputs/test/pipe_spec.yue",
108 "spec/inputs/test/try_catch_spec.yue",
109 "spec/inputs/test/comprehension_spec.yue"
98} 110}
99local yue = require("yue") 111local yue = require("yue")
100local rewriteLineCol 112local rewriteLineCol
diff --git a/spec/outputs/test/nil_coalescing_spec.lua b/spec/outputs/test/nil_coalescing_spec.lua
new file mode 100644
index 0000000..90b2a64
--- /dev/null
+++ b/spec/outputs/test/nil_coalescing_spec.lua
@@ -0,0 +1,23 @@
1local _anon_func_0 = function(a, b)
2 if a ~= nil then
3 return a
4 else
5 return b
6 end
7end
8local _anon_func_1 = function(a, c)
9 if a ~= nil then
10 return a
11 else
12 return c
13 end
14end
15return describe("nil coalescing", function()
16 return it("distinguish nil and false", function()
17 local a = nil
18 local b = false
19 local c = 0
20 assert.same((_anon_func_0(a, b)), false)
21 return assert.same((_anon_func_1(a, c)), 0)
22 end)
23end)
diff --git a/spec/outputs/test/pipe_spec.lua b/spec/outputs/test/pipe_spec.lua
new file mode 100644
index 0000000..3d797ed
--- /dev/null
+++ b/spec/outputs/test/pipe_spec.lua
@@ -0,0 +1,13 @@
1return describe("pipe", function()
2 return it("pipes through functions", function()
3 local f
4 f = function(x)
5 return x + 1
6 end
7 local g
8 g = function(x)
9 return x * 2
10 end
11 return assert.same((g(f(3))), 8)
12 end)
13end)
diff --git a/spec/outputs/test/try_catch_spec.lua b/spec/outputs/test/try_catch_spec.lua
new file mode 100644
index 0000000..2bcfc16
--- /dev/null
+++ b/spec/outputs/test/try_catch_spec.lua
@@ -0,0 +1,17 @@
1return describe("try/catch", function()
2 return it("catch and rethrow", function()
3 local ok, success, err = pcall(function()
4 return xpcall(function()
5 return error("boom")
6 end, function(e)
7 local _, result = pcall(function()
8 return error("wrap:" .. e:match("^.-:%d+:%s*(.*)$"))
9 end)
10 return result
11 end)
12 end)
13 assert.same(ok, true)
14 assert.same(success, false)
15 return assert.is_true(err:match("wrap:boom") ~= nil)
16 end)
17end)