diff options
Diffstat (limited to 'spec/outputs')
| -rw-r--r-- | spec/outputs/comprehension_nested.lua | 24 | ||||
| -rw-r--r-- | spec/outputs/destructure_defaults.lua | 15 | ||||
| -rw-r--r-- | spec/outputs/export_mixed.lua | 11 | ||||
| -rw-r--r-- | spec/outputs/nil_coalesce_precedence.lua | 24 | ||||
| -rw-r--r-- | spec/outputs/pipe_chain_combo.lua | 9 | ||||
| -rw-r--r-- | spec/outputs/test/comprehension_spec.lua | 31 | ||||
| -rw-r--r-- | spec/outputs/test/destructure_spec.lua | 29 | ||||
| -rw-r--r-- | spec/outputs/test/format_spec.lua | 14 | ||||
| -rw-r--r-- | spec/outputs/test/nil_coalescing_spec.lua | 23 | ||||
| -rw-r--r-- | spec/outputs/test/pipe_spec.lua | 13 | ||||
| -rw-r--r-- | spec/outputs/test/try_catch_spec.lua | 17 | ||||
| -rw-r--r-- | spec/outputs/unicode/pipe_chain_combo.lua | 9 | ||||
| -rw-r--r-- | spec/outputs/with_scope_shadow.lua | 14 |
13 files changed, 232 insertions, 1 deletions
diff --git a/spec/outputs/comprehension_nested.lua b/spec/outputs/comprehension_nested.lua new file mode 100644 index 0000000..abd5792 --- /dev/null +++ b/spec/outputs/comprehension_nested.lua | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | local list = { | ||
| 2 | 1, | ||
| 3 | 2, | ||
| 4 | 3 | ||
| 5 | } | ||
| 6 | local pairs | ||
| 7 | do | ||
| 8 | local _accum_0 = { } | ||
| 9 | local _len_0 = 1 | ||
| 10 | for _index_0 = 1, #list do | ||
| 11 | local i = list[_index_0] | ||
| 12 | if i % 2 == 1 then | ||
| 13 | for _index_1 = 1, #list do | ||
| 14 | local j = list[_index_1] | ||
| 15 | if j > i then | ||
| 16 | _accum_0[_len_0] = tostring(i) .. "-" .. tostring(j) | ||
| 17 | _len_0 = _len_0 + 1 | ||
| 18 | end | ||
| 19 | end | ||
| 20 | end | ||
| 21 | end | ||
| 22 | pairs = _accum_0 | ||
| 23 | end | ||
| 24 | return print(table.concat(pairs, ",")) | ||
diff --git a/spec/outputs/destructure_defaults.lua b/spec/outputs/destructure_defaults.lua new file mode 100644 index 0000000..938d9b2 --- /dev/null +++ b/spec/outputs/destructure_defaults.lua | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | local t = { | ||
| 2 | a = 1, | ||
| 3 | b = { | ||
| 4 | c = 3 | ||
| 5 | }, | ||
| 6 | d = nil | ||
| 7 | } | ||
| 8 | local a, c, d, e = t.a, t.b.c, t.b.d, t.e | ||
| 9 | if d == nil then | ||
| 10 | d = 4 | ||
| 11 | end | ||
| 12 | if e == nil then | ||
| 13 | e = 5 | ||
| 14 | end | ||
| 15 | return print(a, c, d, e) | ||
diff --git a/spec/outputs/export_mixed.lua b/spec/outputs/export_mixed.lua new file mode 100644 index 0000000..35529e2 --- /dev/null +++ b/spec/outputs/export_mixed.lua | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | local _module_0 = { } | ||
| 2 | local answer = 42 | ||
| 3 | _module_0["answer"] = answer | ||
| 4 | local foo | ||
| 5 | foo = function() | ||
| 6 | return "bar" | ||
| 7 | end | ||
| 8 | _module_0["foo"] = foo | ||
| 9 | local baz = "baz" | ||
| 10 | _module_0["baz"] = baz | ||
| 11 | return _module_0 | ||
diff --git a/spec/outputs/nil_coalesce_precedence.lua b/spec/outputs/nil_coalesce_precedence.lua new file mode 100644 index 0000000..6f353ee --- /dev/null +++ b/spec/outputs/nil_coalesce_precedence.lua | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | local a = nil | ||
| 2 | local b = false | ||
| 3 | local c = 0 | ||
| 4 | local x | ||
| 5 | if a ~= nil then | ||
| 6 | x = a | ||
| 7 | else | ||
| 8 | do | ||
| 9 | local _exp_0 = (b and 1) | ||
| 10 | if _exp_0 ~= nil then | ||
| 11 | x = _exp_0 | ||
| 12 | else | ||
| 13 | x = (c or 2) | ||
| 14 | end | ||
| 15 | end | ||
| 16 | end | ||
| 17 | local y = ((function() | ||
| 18 | if a ~= nil then | ||
| 19 | return a | ||
| 20 | else | ||
| 21 | return b | ||
| 22 | end | ||
| 23 | end)()) and 1 or 2 | ||
| 24 | return print(x, y) | ||
diff --git a/spec/outputs/pipe_chain_combo.lua b/spec/outputs/pipe_chain_combo.lua new file mode 100644 index 0000000..6cf40a9 --- /dev/null +++ b/spec/outputs/pipe_chain_combo.lua | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | local f1 | ||
| 2 | f1 = function(x) | ||
| 3 | return x + 2 | ||
| 4 | end | ||
| 5 | local f2 | ||
| 6 | f2 = function(x) | ||
| 7 | return x * 3 | ||
| 8 | end | ||
| 9 | local value = print(tostring(f2(f1(3)))) | ||
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 @@ | |||
| 1 | return 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) | ||
| 31 | end) | ||
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 @@ | |||
| 1 | return 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) | ||
| 29 | end) | ||
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 | } |
| 99 | local yue = require("yue") | 111 | local yue = require("yue") |
| 100 | local rewriteLineCol | 112 | local 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 @@ | |||
| 1 | local _anon_func_0 = function(a, b) | ||
| 2 | if a ~= nil then | ||
| 3 | return a | ||
| 4 | else | ||
| 5 | return b | ||
| 6 | end | ||
| 7 | end | ||
| 8 | local _anon_func_1 = function(a, c) | ||
| 9 | if a ~= nil then | ||
| 10 | return a | ||
| 11 | else | ||
| 12 | return c | ||
| 13 | end | ||
| 14 | end | ||
| 15 | return 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) | ||
| 23 | end) | ||
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 @@ | |||
| 1 | return 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) | ||
| 13 | end) | ||
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 @@ | |||
| 1 | return 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) | ||
| 17 | end) | ||
diff --git a/spec/outputs/unicode/pipe_chain_combo.lua b/spec/outputs/unicode/pipe_chain_combo.lua new file mode 100644 index 0000000..f48cb5b --- /dev/null +++ b/spec/outputs/unicode/pipe_chain_combo.lua | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | local _u52a0 | ||
| 2 | _u52a0 = function(x) | ||
| 3 | return x + 2 | ||
| 4 | end | ||
| 5 | local _u4e58 | ||
| 6 | _u4e58 = function(x) | ||
| 7 | return x * 3 | ||
| 8 | end | ||
| 9 | local _u503c = print(tostring(_u4e58(_u52a0(3)))) | ||
diff --git a/spec/outputs/with_scope_shadow.lua b/spec/outputs/with_scope_shadow.lua new file mode 100644 index 0000000..72abe95 --- /dev/null +++ b/spec/outputs/with_scope_shadow.lua | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | local target = { | ||
| 2 | val = 1, | ||
| 3 | add = function(self, n) | ||
| 4 | self.val = self.val + n | ||
| 5 | return self.val | ||
| 6 | end | ||
| 7 | } | ||
| 8 | local result | ||
| 9 | do | ||
| 10 | local val = 100 | ||
| 11 | add(2) | ||
| 12 | result = target | ||
| 13 | end | ||
| 14 | return print(result, target.val) | ||
