aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--spec/inputs/test/anonymous_class_spec.yue27
-rw-r--r--spec/inputs/test/class_expression_spec.yue27
-rw-r--r--spec/inputs/test/constructor_promotion_spec.yue26
-rw-r--r--spec/inputs/test/continue_spec.yue37
-rw-r--r--spec/inputs/test/export_import_interactions_spec.yue19
-rw-r--r--spec/inputs/test/format_spec.yue7
-rw-r--r--spec/inputs/test/string_interpolation_spec.yue34
-rw-r--r--spec/inputs/test/using_spec.yue47
-rw-r--r--spec/outputs/test/anonymous_class_spec.lua142
-rw-r--r--spec/outputs/test/class_expression_spec.lua110
-rw-r--r--spec/outputs/test/constructor_promotion_spec.lua96
-rw-r--r--spec/outputs/test/continue_spec.lua104
-rw-r--r--spec/outputs/test/export_import_interactions_spec.lua35
-rw-r--r--spec/outputs/test/format_spec.lua7
-rw-r--r--spec/outputs/test/string_interpolation_spec.lua36
-rw-r--r--spec/outputs/test/using_spec.lua50
16 files changed, 804 insertions, 0 deletions
diff --git a/spec/inputs/test/anonymous_class_spec.yue b/spec/inputs/test/anonymous_class_spec.yue
new file mode 100644
index 0000000..72854ee
--- /dev/null
+++ b/spec/inputs/test/anonymous_class_spec.yue
@@ -0,0 +1,27 @@
1describe "anonymous class", ->
2 it "should create anonymous class", ->
3 AnonymousClass = class
4 value: 100
5 getValue: => @value
6
7 instance = AnonymousClass!
8 assert.same instance\getValue!, 100
9
10 it "should use assigned name", ->
11 MyClass = class
12 value: 50
13
14 instance = MyClass!
15 assert.is_true MyClass.__name == "MyClass"
16 assert.same instance.value, 50
17
18 it "should support anonymous subclass", ->
19 Base = class
20 baseMethod: => "base"
21
22 Sub = class extends Base
23 subMethod: => "sub"
24
25 instance = Sub!
26 assert.same instance\baseMethod!, "base"
27 assert.same instance\subMethod!, "sub"
diff --git a/spec/inputs/test/class_expression_spec.yue b/spec/inputs/test/class_expression_spec.yue
new file mode 100644
index 0000000..13c1d23
--- /dev/null
+++ b/spec/inputs/test/class_expression_spec.yue
@@ -0,0 +1,27 @@
1describe "class expression", ->
2 it "should support class expression assignment", ->
3 MyClass = class
4 value: 100
5
6 assert.same MyClass.value, 100
7
8 it "should support class expression in table", ->
9 classes = {
10 Alpha: class
11 new: => @value = 1
12 Beta: class
13 new: => @value = 2
14 }
15
16 a = classes.Alpha!
17 b = classes.Beta!
18 assert.same a.value, 1
19 assert.same b.value, 2
20
21 it "should work with return", ->
22 fn = ->
23 return class
24 value: 50
25
26 Instance = fn!
27 assert.same Instance!.value, 50
diff --git a/spec/inputs/test/constructor_promotion_spec.yue b/spec/inputs/test/constructor_promotion_spec.yue
new file mode 100644
index 0000000..83c9d15
--- /dev/null
+++ b/spec/inputs/test/constructor_promotion_spec.yue
@@ -0,0 +1,26 @@
1describe "constructor promotion", ->
2 it "should promote simple arguments to assignment", ->
3 class Thing
4 new: (@name, @age) =>
5
6 instance = Thing "Alice", 30
7 assert.same instance.name, "Alice"
8 assert.same instance.age, 30
9
10 it "should promote multiple arguments", ->
11 class Point
12 new: (@x, @y, @z) =>
13
14 p = Point 1, 2, 3
15 assert.same p.x, 1
16 assert.same p.y, 2
17 assert.same p.z, 3
18
19 it "should work with multiple parameters", ->
20 class Container
21 new: (@a, @b, @c) =>
22
23 c = Container!
24 assert.same c.a, nil
25 assert.same c.b, nil
26 assert.same c.c, nil
diff --git a/spec/inputs/test/continue_spec.yue b/spec/inputs/test/continue_spec.yue
new file mode 100644
index 0000000..bf4e839
--- /dev/null
+++ b/spec/inputs/test/continue_spec.yue
@@ -0,0 +1,37 @@
1describe "continue statement", ->
2 it "should skip odd numbers in for loop", ->
3 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
4 even = for n in *numbers
5 continue if n % 2 == 1
6 n
7
8 assert.same even, {2, 4, 6, 8, 10}
9
10 it "should filter values in while loop", ->
11 i = 0
12 result = []
13
14 while i < 10
15 i += 1
16 continue if i % 3 == 0
17 table.insert result, i
18
19 assert.same result, {1, 2, 4, 5, 7, 8, 10}
20
21 it "should skip with condition in loop expression", ->
22 items = [1, 2, 3, 4, 5]
23 odds = for item in *items
24 continue if item % 2 == 0
25 item
26
27 assert.same odds, {1, 3, 5}
28
29 it "should work with nested loops", ->
30 result = []
31
32 for i = 1, 5
33 for j = 1, 5
34 continue if i == j
35 table.insert result, {i, j}
36
37 assert.same #result, 20
diff --git a/spec/inputs/test/export_import_interactions_spec.yue b/spec/inputs/test/export_import_interactions_spec.yue
new file mode 100644
index 0000000..8281246
--- /dev/null
+++ b/spec/inputs/test/export_import_interactions_spec.yue
@@ -0,0 +1,19 @@
1describe "export import interactions", ->
2 it "should import with alias and destructuring", ->
3 source = {
4 origin: {x: 10, y: 20}
5 target: "result"
6 point: {x: 5, y: 15}
7 }
8 import x, y from source.origin
9 import target from source
10 px, py = do
11 local x, y
12 import x, y from source.point
13 x, y
14
15 assert.same x, 10
16 assert.same y, 20
17 assert.same target, "result"
18 assert.same px, 5
19 assert.same py, 15
diff --git a/spec/inputs/test/format_spec.yue b/spec/inputs/test/format_spec.yue
index 4da3f7e..2069795 100644
--- a/spec/inputs/test/format_spec.yue
+++ b/spec/inputs/test/format_spec.yue
@@ -55,11 +55,13 @@ files = [
55 "spec/inputs/syntax.yue" 55 "spec/inputs/syntax.yue"
56 "spec/inputs/global.yue" 56 "spec/inputs/global.yue"
57 "spec/inputs/plus.yue" 57 "spec/inputs/plus.yue"
58 "spec/inputs/test/string_interpolation_spec.yue"
58 "spec/inputs/test/with_spec.yue" 59 "spec/inputs/test/with_spec.yue"
59 "spec/inputs/test/try_catch_spec.yue" 60 "spec/inputs/test/try_catch_spec.yue"
60 "spec/inputs/test/operator_advanced_spec.yue" 61 "spec/inputs/test/operator_advanced_spec.yue"
61 "spec/inputs/test/with_statement_spec.yue" 62 "spec/inputs/test/with_statement_spec.yue"
62 "spec/inputs/test/literals_spec.yue" 63 "spec/inputs/test/literals_spec.yue"
64 "spec/inputs/test/continue_spec.yue"
63 "spec/inputs/test/varargs_assignment_spec.yue" 65 "spec/inputs/test/varargs_assignment_spec.yue"
64 "spec/inputs/test/advanced_macro_spec.yue" 66 "spec/inputs/test/advanced_macro_spec.yue"
65 "spec/inputs/test/pipe_spec.yue" 67 "spec/inputs/test/pipe_spec.yue"
@@ -77,11 +79,13 @@ files = [
77 "spec/inputs/test/operators_spec.yue" 79 "spec/inputs/test/operators_spec.yue"
78 "spec/inputs/test/comprehension_spec.yue" 80 "spec/inputs/test/comprehension_spec.yue"
79 "spec/inputs/test/attrib_spec.yue" 81 "spec/inputs/test/attrib_spec.yue"
82 "spec/inputs/test/using_spec.yue"
80 "spec/inputs/test/nil_coalescing_spec.yue" 83 "spec/inputs/test/nil_coalescing_spec.yue"
81 "spec/inputs/test/table_comprehension_spec.yue" 84 "spec/inputs/test/table_comprehension_spec.yue"
82 "spec/inputs/test/slicing_spec.yue" 85 "spec/inputs/test/slicing_spec.yue"
83 "spec/inputs/test/close_attribute_spec.yue" 86 "spec/inputs/test/close_attribute_spec.yue"
84 "spec/inputs/test/named_varargs_spec.yue" 87 "spec/inputs/test/named_varargs_spec.yue"
88 "spec/inputs/test/export_import_interactions_spec.yue"
85 "spec/inputs/test/table_spreading_spec.yue" 89 "spec/inputs/test/table_spreading_spec.yue"
86 "spec/inputs/test/macro_spec.yue" 90 "spec/inputs/test/macro_spec.yue"
87 "spec/inputs/test/chaining_comparison_spec.yue" 91 "spec/inputs/test/chaining_comparison_spec.yue"
@@ -89,10 +93,13 @@ files = [
89 "spec/inputs/test/destructure_spec.yue" 93 "spec/inputs/test/destructure_spec.yue"
90 "spec/inputs/test/vararg_spec.yue" 94 "spec/inputs/test/vararg_spec.yue"
91 "spec/inputs/test/string_spec.yue" 95 "spec/inputs/test/string_spec.yue"
96 "spec/inputs/test/anonymous_class_spec.yue"
92 "spec/inputs/test/implicit_object_spec.yue" 97 "spec/inputs/test/implicit_object_spec.yue"
98 "spec/inputs/test/constructor_promotion_spec.yue"
93 "spec/inputs/test/backcall_spec.yue" 99 "spec/inputs/test/backcall_spec.yue"
94 "spec/inputs/test/while_assignment_spec.yue" 100 "spec/inputs/test/while_assignment_spec.yue"
95 "spec/inputs/test/switch_spec.yue" 101 "spec/inputs/test/switch_spec.yue"
102 "spec/inputs/test/class_expression_spec.yue"
96 "spec/inputs/test/functions_advanced_spec.yue" 103 "spec/inputs/test/functions_advanced_spec.yue"
97 "spec/inputs/test/config_spec.yue" 104 "spec/inputs/test/config_spec.yue"
98 "spec/inputs/test/yaml_string_spec.yue" 105 "spec/inputs/test/yaml_string_spec.yue"
diff --git a/spec/inputs/test/string_interpolation_spec.yue b/spec/inputs/test/string_interpolation_spec.yue
new file mode 100644
index 0000000..02b1606
--- /dev/null
+++ b/spec/inputs/test/string_interpolation_spec.yue
@@ -0,0 +1,34 @@
1describe "string interpolation", ->
2 it "should interpolate in double quotes", ->
3 name = "World"
4 result = "Hello #{name}!"
5 assert.same result, "Hello World!"
6
7 it "should interpolate numbers", ->
8 a, b = 10, 20
9 result = "#{a} + #{b} = #{a + b}"
10 assert.same result, "10 + 20 = 30"
11
12 it "should interpolate expressions", ->
13 x = 5
14 result = "x * 2 = #{x * 2}"
15 assert.same result, "x * 2 = 10"
16
17 it "should interpolate function calls", ->
18 result = "result: #{math.floor 5.5}"
19 assert.same result, "result: 5"
20
21 it "should interpolate in string literals", ->
22 x = 100
23 result = "Value: #{x}"
24 assert.same result, "Value: 100"
25
26 it "should work with nested interpolation", ->
27 inner = "inner"
28 result = "Outer: #{inner}"
29 assert.same result, "Outer: inner"
30
31 it "should not interpolate in single quotes", ->
32 name = "World"
33 result = 'Hello #{name}!'
34 assert.same result, 'Hello #{name}!'
diff --git a/spec/inputs/test/using_spec.yue b/spec/inputs/test/using_spec.yue
new file mode 100644
index 0000000..e9ad749
--- /dev/null
+++ b/spec/inputs/test/using_spec.yue
@@ -0,0 +1,47 @@
1describe "using", ->
2 it "should prevent variable shadowing in assignment", ->
3 tmp = 100
4 i, k = 100, 50
5
6 process = (add using k, i) ->
7 tmp = tmp + add
8 i += tmp
9 k += tmp
10
11 process 22
12 assert.same i, 222
13 assert.same k, 172
14 assert.same tmp, 100
15
16 it "should handle multiple variable names", ->
17 a, b, c = 1, 2, 3
18
19 process = (sum using a, b) ->
20 a += 1
21 b += 2
22 c = sum + 100
23
24 process 10
25 assert.same a, 2
26 assert.same b, 4
27 assert.same c, 3
28
29 it "should work with nil value", ->
30 local x = 1
31
32 fn = (val using x) ->
33 if val ~= nil
34 x = val
35
36 fn 100
37 assert.same x, 100
38 assert.is_true x ~= 1
39
40 it "should work with function calls", ->
41 local count = 0
42
43 fn = (n using count) ->
44 count += n
45
46 fn 5
47 assert.same count, 5
diff --git a/spec/outputs/test/anonymous_class_spec.lua b/spec/outputs/test/anonymous_class_spec.lua
new file mode 100644
index 0000000..8f6a122
--- /dev/null
+++ b/spec/outputs/test/anonymous_class_spec.lua
@@ -0,0 +1,142 @@
1return describe("anonymous class", function()
2 it("should create anonymous class", function()
3 local AnonymousClass
4 do
5 local _class_0
6 local _base_0 = {
7 value = 100,
8 getValue = function(self)
9 return self.value
10 end
11 }
12 if _base_0.__index == nil then
13 _base_0.__index = _base_0
14 end
15 _class_0 = setmetatable({
16 __init = function() end,
17 __base = _base_0,
18 __name = "AnonymousClass"
19 }, {
20 __index = _base_0,
21 __call = function(cls, ...)
22 local _self_0 = setmetatable({ }, _base_0)
23 cls.__init(_self_0, ...)
24 return _self_0
25 end
26 })
27 _base_0.__class = _class_0
28 AnonymousClass = _class_0
29 end
30 local instance = AnonymousClass()
31 return assert.same(instance:getValue(), 100)
32 end)
33 it("should use assigned name", function()
34 local MyClass
35 do
36 local _class_0
37 local _base_0 = {
38 value = 50
39 }
40 if _base_0.__index == nil then
41 _base_0.__index = _base_0
42 end
43 _class_0 = setmetatable({
44 __init = function() end,
45 __base = _base_0,
46 __name = "MyClass"
47 }, {
48 __index = _base_0,
49 __call = function(cls, ...)
50 local _self_0 = setmetatable({ }, _base_0)
51 cls.__init(_self_0, ...)
52 return _self_0
53 end
54 })
55 _base_0.__class = _class_0
56 MyClass = _class_0
57 end
58 local instance = MyClass()
59 assert.is_true(MyClass.__name == "MyClass")
60 return assert.same(instance.value, 50)
61 end)
62 return it("should support anonymous subclass", function()
63 local Base
64 do
65 local _class_0
66 local _base_0 = {
67 baseMethod = function(self)
68 return "base"
69 end
70 }
71 if _base_0.__index == nil then
72 _base_0.__index = _base_0
73 end
74 _class_0 = setmetatable({
75 __init = function() end,
76 __base = _base_0,
77 __name = "Base"
78 }, {
79 __index = _base_0,
80 __call = function(cls, ...)
81 local _self_0 = setmetatable({ }, _base_0)
82 cls.__init(_self_0, ...)
83 return _self_0
84 end
85 })
86 _base_0.__class = _class_0
87 Base = _class_0
88 end
89 local Sub
90 do
91 local _class_0
92 local _parent_0 = Base
93 local _base_0 = {
94 subMethod = function(self)
95 return "sub"
96 end
97 }
98 for _key_0, _val_0 in pairs(_parent_0.__base) do
99 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
100 _base_0[_key_0] = _val_0
101 end
102 end
103 if _base_0.__index == nil then
104 _base_0.__index = _base_0
105 end
106 setmetatable(_base_0, _parent_0.__base)
107 _class_0 = setmetatable({
108 __init = function(self, ...)
109 return _class_0.__parent.__init(self, ...)
110 end,
111 __base = _base_0,
112 __name = "Sub",
113 __parent = _parent_0
114 }, {
115 __index = function(cls, name)
116 local val = rawget(_base_0, name)
117 if val == nil then
118 local parent = rawget(cls, "__parent")
119 if parent then
120 return parent[name]
121 end
122 else
123 return val
124 end
125 end,
126 __call = function(cls, ...)
127 local _self_0 = setmetatable({ }, _base_0)
128 cls.__init(_self_0, ...)
129 return _self_0
130 end
131 })
132 _base_0.__class = _class_0
133 if _parent_0.__inherited then
134 _parent_0.__inherited(_parent_0, _class_0)
135 end
136 Sub = _class_0
137 end
138 local instance = Sub()
139 assert.same(instance:baseMethod(), "base")
140 return assert.same(instance:subMethod(), "sub")
141 end)
142end)
diff --git a/spec/outputs/test/class_expression_spec.lua b/spec/outputs/test/class_expression_spec.lua
new file mode 100644
index 0000000..fd9083b
--- /dev/null
+++ b/spec/outputs/test/class_expression_spec.lua
@@ -0,0 +1,110 @@
1local _anon_func_0 = function(setmetatable)
2 local _class_0
3 local _base_0 = { }
4 if _base_0.__index == nil then
5 _base_0.__index = _base_0
6 end
7 _class_0 = setmetatable({
8 __init = function(self)
9 self.value = 1
10 end,
11 __base = _base_0
12 }, {
13 __index = _base_0,
14 __call = function(cls, ...)
15 local _self_0 = setmetatable({ }, _base_0)
16 cls.__init(_self_0, ...)
17 return _self_0
18 end
19 })
20 _base_0.__class = _class_0
21 return _class_0
22end
23local _anon_func_1 = function(setmetatable)
24 local _class_0
25 local _base_0 = { }
26 if _base_0.__index == nil then
27 _base_0.__index = _base_0
28 end
29 _class_0 = setmetatable({
30 __init = function(self)
31 self.value = 2
32 end,
33 __base = _base_0
34 }, {
35 __index = _base_0,
36 __call = function(cls, ...)
37 local _self_0 = setmetatable({ }, _base_0)
38 cls.__init(_self_0, ...)
39 return _self_0
40 end
41 })
42 _base_0.__class = _class_0
43 return _class_0
44end
45return describe("class expression", function()
46 it("should support class expression assignment", function()
47 local MyClass
48 do
49 local _class_0
50 local _base_0 = {
51 value = 100
52 }
53 if _base_0.__index == nil then
54 _base_0.__index = _base_0
55 end
56 _class_0 = setmetatable({
57 __init = function() end,
58 __base = _base_0,
59 __name = "MyClass"
60 }, {
61 __index = _base_0,
62 __call = function(cls, ...)
63 local _self_0 = setmetatable({ }, _base_0)
64 cls.__init(_self_0, ...)
65 return _self_0
66 end
67 })
68 _base_0.__class = _class_0
69 MyClass = _class_0
70 end
71 return assert.same(MyClass.value, 100)
72 end)
73 it("should support class expression in table", function()
74 local classes = {
75 Alpha = _anon_func_0(setmetatable),
76 Beta = _anon_func_1(setmetatable)
77 }
78 local a = classes.Alpha()
79 local b = classes.Beta()
80 assert.same(a.value, 1)
81 return assert.same(b.value, 2)
82 end)
83 return it("should work with return", function()
84 local fn
85 fn = function()
86 local _class_0
87 local _base_0 = {
88 value = 50
89 }
90 if _base_0.__index == nil then
91 _base_0.__index = _base_0
92 end
93 _class_0 = setmetatable({
94 __init = function() end,
95 __base = _base_0
96 }, {
97 __index = _base_0,
98 __call = function(cls, ...)
99 local _self_0 = setmetatable({ }, _base_0)
100 cls.__init(_self_0, ...)
101 return _self_0
102 end
103 })
104 _base_0.__class = _class_0
105 return _class_0
106 end
107 local Instance = fn()
108 return assert.same(Instance().value, 50)
109 end)
110end)
diff --git a/spec/outputs/test/constructor_promotion_spec.lua b/spec/outputs/test/constructor_promotion_spec.lua
new file mode 100644
index 0000000..5caa762
--- /dev/null
+++ b/spec/outputs/test/constructor_promotion_spec.lua
@@ -0,0 +1,96 @@
1return describe("constructor promotion", function()
2 it("should promote simple arguments to assignment", function()
3 local Thing
4 do
5 local _class_0
6 local _base_0 = { }
7 if _base_0.__index == nil then
8 _base_0.__index = _base_0
9 end
10 _class_0 = setmetatable({
11 __init = function(self, name, age)
12 self.name = name
13 self.age = age
14 end,
15 __base = _base_0,
16 __name = "Thing"
17 }, {
18 __index = _base_0,
19 __call = function(cls, ...)
20 local _self_0 = setmetatable({ }, _base_0)
21 cls.__init(_self_0, ...)
22 return _self_0
23 end
24 })
25 _base_0.__class = _class_0
26 Thing = _class_0
27 end
28 local instance = Thing("Alice", 30)
29 assert.same(instance.name, "Alice")
30 return assert.same(instance.age, 30)
31 end)
32 it("should promote multiple arguments", function()
33 local Point
34 do
35 local _class_0
36 local _base_0 = { }
37 if _base_0.__index == nil then
38 _base_0.__index = _base_0
39 end
40 _class_0 = setmetatable({
41 __init = function(self, x, y, z)
42 self.x = x
43 self.y = y
44 self.z = z
45 end,
46 __base = _base_0,
47 __name = "Point"
48 }, {
49 __index = _base_0,
50 __call = function(cls, ...)
51 local _self_0 = setmetatable({ }, _base_0)
52 cls.__init(_self_0, ...)
53 return _self_0
54 end
55 })
56 _base_0.__class = _class_0
57 Point = _class_0
58 end
59 local p = Point(1, 2, 3)
60 assert.same(p.x, 1)
61 assert.same(p.y, 2)
62 return assert.same(p.z, 3)
63 end)
64 return it("should work with multiple parameters", function()
65 local Container
66 do
67 local _class_0
68 local _base_0 = { }
69 if _base_0.__index == nil then
70 _base_0.__index = _base_0
71 end
72 _class_0 = setmetatable({
73 __init = function(self, a, b, c)
74 self.a = a
75 self.b = b
76 self.c = c
77 end,
78 __base = _base_0,
79 __name = "Container"
80 }, {
81 __index = _base_0,
82 __call = function(cls, ...)
83 local _self_0 = setmetatable({ }, _base_0)
84 cls.__init(_self_0, ...)
85 return _self_0
86 end
87 })
88 _base_0.__class = _class_0
89 Container = _class_0
90 end
91 local c = Container()
92 assert.same(c.a, nil)
93 assert.same(c.b, nil)
94 return assert.same(c.c, nil)
95 end)
96end)
diff --git a/spec/outputs/test/continue_spec.lua b/spec/outputs/test/continue_spec.lua
new file mode 100644
index 0000000..8c73aee
--- /dev/null
+++ b/spec/outputs/test/continue_spec.lua
@@ -0,0 +1,104 @@
1return describe("continue statement", function()
2 it("should skip odd numbers in for loop", function()
3 local numbers = {
4 1,
5 2,
6 3,
7 4,
8 5,
9 6,
10 7,
11 8,
12 9,
13 10
14 }
15 local even
16 do
17 local _accum_0 = { }
18 local _len_0 = 1
19 for _index_0 = 1, #numbers do
20 local n = numbers[_index_0]
21 if n % 2 == 1 then
22 goto _continue_0
23 end
24 _accum_0[_len_0] = n
25 _len_0 = _len_0 + 1
26 ::_continue_0::
27 end
28 even = _accum_0
29 end
30 return assert.same(even, {
31 2,
32 4,
33 6,
34 8,
35 10
36 })
37 end)
38 it("should filter values in while loop", function()
39 local i = 0
40 local result = { }
41 while i < 10 do
42 i = i + 1
43 if i % 3 == 0 then
44 goto _continue_0
45 end
46 table.insert(result, i)
47 ::_continue_0::
48 end
49 return assert.same(result, {
50 1,
51 2,
52 4,
53 5,
54 7,
55 8,
56 10
57 })
58 end)
59 it("should skip with condition in loop expression", function()
60 local items = {
61 1,
62 2,
63 3,
64 4,
65 5
66 }
67 local odds
68 do
69 local _accum_0 = { }
70 local _len_0 = 1
71 for _index_0 = 1, #items do
72 local item = items[_index_0]
73 if item % 2 == 0 then
74 goto _continue_0
75 end
76 _accum_0[_len_0] = item
77 _len_0 = _len_0 + 1
78 ::_continue_0::
79 end
80 odds = _accum_0
81 end
82 return assert.same(odds, {
83 1,
84 3,
85 5
86 })
87 end)
88 return it("should work with nested loops", function()
89 local result = { }
90 for i = 1, 5 do
91 for j = 1, 5 do
92 if i == j then
93 goto _continue_0
94 end
95 table.insert(result, {
96 i,
97 j
98 })
99 ::_continue_0::
100 end
101 end
102 return assert.same(#result, 20)
103 end)
104end)
diff --git a/spec/outputs/test/export_import_interactions_spec.lua b/spec/outputs/test/export_import_interactions_spec.lua
new file mode 100644
index 0000000..774d57a
--- /dev/null
+++ b/spec/outputs/test/export_import_interactions_spec.lua
@@ -0,0 +1,35 @@
1return describe("export import interactions", function()
2 return it("should import with alias and destructuring", function()
3 local source = {
4 origin = {
5 x = 10,
6 y = 20
7 },
8 target = "result",
9 point = {
10 x = 5,
11 y = 15
12 }
13 }
14 local x, y
15 do
16 local _obj_0 = source.origin
17 x, y = _obj_0.x, _obj_0.y
18 end
19 local target = source.target
20 local px, py
21 do
22 local x, y
23 do
24 local _obj_0 = source.point
25 x, y = _obj_0.x, _obj_0.y
26 end
27 px, py = x, y
28 end
29 assert.same(x, 10)
30 assert.same(y, 20)
31 assert.same(target, "result")
32 assert.same(px, 5)
33 return assert.same(py, 15)
34 end)
35end)
diff --git a/spec/outputs/test/format_spec.lua b/spec/outputs/test/format_spec.lua
index 8307f6a..bb31d50 100644
--- a/spec/outputs/test/format_spec.lua
+++ b/spec/outputs/test/format_spec.lua
@@ -55,11 +55,13 @@ local files = {
55 "spec/inputs/syntax.yue", 55 "spec/inputs/syntax.yue",
56 "spec/inputs/global.yue", 56 "spec/inputs/global.yue",
57 "spec/inputs/plus.yue", 57 "spec/inputs/plus.yue",
58 "spec/inputs/test/string_interpolation_spec.yue",
58 "spec/inputs/test/with_spec.yue", 59 "spec/inputs/test/with_spec.yue",
59 "spec/inputs/test/try_catch_spec.yue", 60 "spec/inputs/test/try_catch_spec.yue",
60 "spec/inputs/test/operator_advanced_spec.yue", 61 "spec/inputs/test/operator_advanced_spec.yue",
61 "spec/inputs/test/with_statement_spec.yue", 62 "spec/inputs/test/with_statement_spec.yue",
62 "spec/inputs/test/literals_spec.yue", 63 "spec/inputs/test/literals_spec.yue",
64 "spec/inputs/test/continue_spec.yue",
63 "spec/inputs/test/varargs_assignment_spec.yue", 65 "spec/inputs/test/varargs_assignment_spec.yue",
64 "spec/inputs/test/advanced_macro_spec.yue", 66 "spec/inputs/test/advanced_macro_spec.yue",
65 "spec/inputs/test/pipe_spec.yue", 67 "spec/inputs/test/pipe_spec.yue",
@@ -77,11 +79,13 @@ local files = {
77 "spec/inputs/test/operators_spec.yue", 79 "spec/inputs/test/operators_spec.yue",
78 "spec/inputs/test/comprehension_spec.yue", 80 "spec/inputs/test/comprehension_spec.yue",
79 "spec/inputs/test/attrib_spec.yue", 81 "spec/inputs/test/attrib_spec.yue",
82 "spec/inputs/test/using_spec.yue",
80 "spec/inputs/test/nil_coalescing_spec.yue", 83 "spec/inputs/test/nil_coalescing_spec.yue",
81 "spec/inputs/test/table_comprehension_spec.yue", 84 "spec/inputs/test/table_comprehension_spec.yue",
82 "spec/inputs/test/slicing_spec.yue", 85 "spec/inputs/test/slicing_spec.yue",
83 "spec/inputs/test/close_attribute_spec.yue", 86 "spec/inputs/test/close_attribute_spec.yue",
84 "spec/inputs/test/named_varargs_spec.yue", 87 "spec/inputs/test/named_varargs_spec.yue",
88 "spec/inputs/test/export_import_interactions_spec.yue",
85 "spec/inputs/test/table_spreading_spec.yue", 89 "spec/inputs/test/table_spreading_spec.yue",
86 "spec/inputs/test/macro_spec.yue", 90 "spec/inputs/test/macro_spec.yue",
87 "spec/inputs/test/chaining_comparison_spec.yue", 91 "spec/inputs/test/chaining_comparison_spec.yue",
@@ -89,10 +93,13 @@ local files = {
89 "spec/inputs/test/destructure_spec.yue", 93 "spec/inputs/test/destructure_spec.yue",
90 "spec/inputs/test/vararg_spec.yue", 94 "spec/inputs/test/vararg_spec.yue",
91 "spec/inputs/test/string_spec.yue", 95 "spec/inputs/test/string_spec.yue",
96 "spec/inputs/test/anonymous_class_spec.yue",
92 "spec/inputs/test/implicit_object_spec.yue", 97 "spec/inputs/test/implicit_object_spec.yue",
98 "spec/inputs/test/constructor_promotion_spec.yue",
93 "spec/inputs/test/backcall_spec.yue", 99 "spec/inputs/test/backcall_spec.yue",
94 "spec/inputs/test/while_assignment_spec.yue", 100 "spec/inputs/test/while_assignment_spec.yue",
95 "spec/inputs/test/switch_spec.yue", 101 "spec/inputs/test/switch_spec.yue",
102 "spec/inputs/test/class_expression_spec.yue",
96 "spec/inputs/test/functions_advanced_spec.yue", 103 "spec/inputs/test/functions_advanced_spec.yue",
97 "spec/inputs/test/config_spec.yue", 104 "spec/inputs/test/config_spec.yue",
98 "spec/inputs/test/yaml_string_spec.yue", 105 "spec/inputs/test/yaml_string_spec.yue",
diff --git a/spec/outputs/test/string_interpolation_spec.lua b/spec/outputs/test/string_interpolation_spec.lua
new file mode 100644
index 0000000..abf23eb
--- /dev/null
+++ b/spec/outputs/test/string_interpolation_spec.lua
@@ -0,0 +1,36 @@
1return describe("string interpolation", function()
2 it("should interpolate in double quotes", function()
3 local name = "World"
4 local result = "Hello " .. tostring(name) .. "!"
5 return assert.same(result, "Hello World!")
6 end)
7 it("should interpolate numbers", function()
8 local a, b = 10, 20
9 local result = tostring(a) .. " + " .. tostring(b) .. " = " .. tostring(a + b)
10 return assert.same(result, "10 + 20 = 30")
11 end)
12 it("should interpolate expressions", function()
13 local x = 5
14 local result = "x * 2 = " .. tostring(x * 2)
15 return assert.same(result, "x * 2 = 10")
16 end)
17 it("should interpolate function calls", function()
18 local result = "result: " .. tostring(math.floor(5.5))
19 return assert.same(result, "result: 5")
20 end)
21 it("should interpolate in string literals", function()
22 local x = 100
23 local result = "Value: " .. tostring(x)
24 return assert.same(result, "Value: 100")
25 end)
26 it("should work with nested interpolation", function()
27 local inner = "inner"
28 local result = "Outer: " .. tostring(inner)
29 return assert.same(result, "Outer: inner")
30 end)
31 return it("should not interpolate in single quotes", function()
32 local name = "World"
33 local result = 'Hello #{name}!'
34 return assert.same(result, 'Hello #{name}!')
35 end)
36end)
diff --git a/spec/outputs/test/using_spec.lua b/spec/outputs/test/using_spec.lua
new file mode 100644
index 0000000..5c2f357
--- /dev/null
+++ b/spec/outputs/test/using_spec.lua
@@ -0,0 +1,50 @@
1return describe("using", function()
2 it("should prevent variable shadowing in assignment", function()
3 local tmp = 100
4 local i, k = 100, 50
5 local process
6 process = function(add)
7 local tmp = tmp + add
8 i = i + tmp
9 k = k + tmp
10 end
11 process(22)
12 assert.same(i, 222)
13 assert.same(k, 172)
14 return assert.same(tmp, 100)
15 end)
16 it("should handle multiple variable names", function()
17 local a, b, c = 1, 2, 3
18 local process
19 process = function(sum)
20 a = a + 1
21 b = b + 2
22 local c = sum + 100
23 end
24 process(10)
25 assert.same(a, 2)
26 assert.same(b, 4)
27 return assert.same(c, 3)
28 end)
29 it("should work with nil value", function()
30 local x = 1
31 local fn
32 fn = function(val)
33 if val ~= nil then
34 x = val
35 end
36 end
37 fn(100)
38 assert.same(x, 100)
39 return assert.is_true(x ~= 1)
40 end)
41 return it("should work with function calls", function()
42 local count = 0
43 local fn
44 fn = function(n)
45 count = count + n
46 end
47 fn(5)
48 return assert.same(count, 5)
49 end)
50end)