aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/multiline_args_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/test/multiline_args_spec.lua')
-rw-r--r--spec/outputs/test/multiline_args_spec.lua219
1 files changed, 219 insertions, 0 deletions
diff --git a/spec/outputs/test/multiline_args_spec.lua b/spec/outputs/test/multiline_args_spec.lua
new file mode 100644
index 0000000..562c571
--- /dev/null
+++ b/spec/outputs/test/multiline_args_spec.lua
@@ -0,0 +1,219 @@
1return describe("multiline arguments", function()
2 it("should split arguments across lines", function()
3 local sum
4 sum = function(a, b, c, d, e, f)
5 return a + b + c + d + e + f
6 end
7 local result = sum(5, 4, 3, 8, 9, 10)
8 return assert.same(result, 39)
9 end)
10 it("should handle nested function calls", function()
11 local outer
12 outer = function(a, b, c, d, e, f)
13 return a + b + c + d + e + f
14 end
15 local result = outer(5, 6, 7, 6, 2, 3)
16 return assert.same(result, 29)
17 end)
18 it("should work with string arguments", function()
19 local fn
20 fn = function(a, b, c, d)
21 return a .. b .. c .. d
22 end
23 local result = fn("hello", " ", "world", "!")
24 return assert.same(result, "hello world!")
25 end)
26 it("should support table arguments", function()
27 local fn
28 fn = function(a, b, c)
29 return {
30 a,
31 b,
32 c
33 }
34 end
35 local result = fn({
36 1,
37 2
38 }, {
39 3,
40 4
41 }, {
42 5,
43 6
44 })
45 return assert.same(result, {
46 {
47 1,
48 2
49 },
50 {
51 3,
52 4
53 },
54 {
55 5,
56 6
57 }
58 })
59 end)
60 it("should handle mixed types", function()
61 local fn
62 fn = function(a, b, c, d)
63 return {
64 a,
65 b,
66 c,
67 d
68 }
69 end
70 local result = fn("text", 123, true, nil)
71 return assert.same(result, {
72 "text",
73 123,
74 true,
75 nil
76 })
77 end)
78 it("should work in table literal", function()
79 local fn
80 fn = function(a, b)
81 return a + b
82 end
83 local result = {
84 1,
85 2,
86 3,
87 4,
88 fn(4, 5, 5, 6),
89 8,
90 9,
91 10
92 }
93 return assert.same(result, {
94 1,
95 2,
96 3,
97 4,
98 9,
99 8,
100 9,
101 10
102 })
103 end)
104 it("should handle deeply nested indentation", function()
105 local fn
106 fn = function(a, b, c, d, e, f, g)
107 return a + b + c + d + e + f + g
108 end
109 local y = {
110 fn(1, 2, 3, 4, 5, 6, 7)
111 }
112 local result = y[1]
113 return assert.same(result, 28)
114 end)
115 it("should work with conditional statements", function()
116 local fn
117 fn = function(a, b, c, d, e, f)
118 return a + b + c + d + e + f
119 end
120 local result1 = fn(1, 2, 3, 4, 5, 6)
121 local result
122 if result1 > 20 then
123 result = "yes"
124 else
125 result = "no"
126 end
127 return assert.same(result, "yes")
128 end)
129 it("should support function expressions", function()
130 local doublePlus
131 doublePlus = function(x, y)
132 return x * 2 + y
133 end
134 local result = doublePlus(5, 10)
135 return assert.same(result, 20)
136 end)
137 it("should handle chained function calls", function()
138 local add
139 add = function(a, b, c, d)
140 return a + b + c + d
141 end
142 local multiply
143 multiply = function(a, b, c, d)
144 return a * b * c * d
145 end
146 local result = multiply(1, 2, 3, 4)
147 return assert.same(result, 24)
148 end)
149 it("should work with method calls", function()
150 local obj = {
151 value = 10,
152 add = function(self, a, b, c)
153 return self.value + a + b + c
154 end
155 }
156 local result = obj:add(5, 10, 15)
157 return assert.same(result, 40)
158 end)
159 it("should support many arguments", function()
160 local sum_many
161 sum_many = function(...)
162 local total = 0
163 for i = 1, select('#', ...) do
164 if type(select(i, ...)) == "number" then
165 total = total + select(i, ...)
166 end
167 end
168 return total
169 end
170 local result = sum_many(1, 2, 3, 4, 5, 6, 7, 8, 9)
171 return assert.same(result, 45)
172 end)
173 it("should work with return statement", function()
174 local fn
175 fn = function(a, b, c)
176 return a + b + c
177 end
178 local get_value
179 get_value = function()
180 return fn(10, 20, 30)
181 end
182 local result = get_value()
183 return assert.same(result, 60)
184 end)
185 it("should handle default parameters", function()
186 local fn
187 fn = function(a, b, c)
188 if a == nil then
189 a = 1
190 end
191 if b == nil then
192 b = 2
193 end
194 if c == nil then
195 c = 3
196 end
197 return a + b + c
198 end
199 local result = fn(10, 20, 30)
200 return assert.same(result, 60)
201 end)
202 return it("should work with varargs", function()
203 local collect
204 collect = function(...)
205 return {
206 ...
207 }
208 end
209 local result = collect(1, 2, 3, 4, 5, 6)
210 return assert.same(result, {
211 1,
212 2,
213 3,
214 4,
215 5,
216 6
217 })
218 end)
219end)