aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/whitespace_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/test/whitespace_spec.lua')
-rw-r--r--spec/outputs/test/whitespace_spec.lua159
1 files changed, 159 insertions, 0 deletions
diff --git a/spec/outputs/test/whitespace_spec.lua b/spec/outputs/test/whitespace_spec.lua
new file mode 100644
index 0000000..ca9116e
--- /dev/null
+++ b/spec/outputs/test/whitespace_spec.lua
@@ -0,0 +1,159 @@
1return describe("whitespace", function()
2 it("should support semicolon statement separator", function()
3 local a = 1
4 local b = 2
5 local result = a + b
6 return assert.same(result, 3)
7 end)
8 it("should handle multiple statements on one line", function()
9 local x = 10
10 local y = 20
11 local z = x + y
12 return assert.same(z, 30)
13 end)
14 it("should work with semicolon in function", function()
15 local fn
16 fn = function()
17 local a = 1
18 local b = 2
19 return a + b
20 end
21 return assert.same(fn(), 3)
22 end)
23 it("should support multiline chaining", function()
24 local obj = {
25 value = 10,
26 add = function(self, n)
27 self.value = self.value + n
28 return self
29 end,
30 get = function(self)
31 return self.value
32 end
33 }
34 local result = obj:add(5):add(10):get()
35 return assert.same(result, 25)
36 end)
37 it("should handle multiline method calls", function()
38 local str = " hello "
39 local result = str:match("^%s*(.-)%s*$"):upper()
40 return assert.same(result, "HELLO")
41 end)
42 it("should work with nested chaining", function()
43 local obj = {
44 level1 = {
45 level2 = {
46 level3 = function(self)
47 return "deep"
48 end
49 }
50 }
51 }
52 local result = obj.level1.level2:level3()
53 return assert.same(result, "deep")
54 end)
55 it("should support chaining with conditionals", function()
56 local obj = {
57 value = 10,
58 isPositive = function(self)
59 return self.value > 0
60 end
61 }
62 local result = obj:isPositive()
63 return assert.is_true(result)
64 end)
65 it("should work with pipe in chaining", function()
66 local result = table.concat((function(tb)
67 local _accum_0 = { }
68 local _len_0 = 1
69 for _index_0 = 1, #tb do
70 local x = tb[_index_0]
71 _accum_0[_len_0] = x * 2
72 _len_0 = _len_0 + 1
73 end
74 return _accum_0
75 end)({
76 1,
77 2,
78 3
79 }))
80 return assert.same(result, "246")
81 end)
82 it("should handle mixed separators", function()
83 local a = 1
84 local b = 2
85 local c = 3
86 local d = 4
87 local result = a + b + c + d
88 return assert.same(result, 10)
89 end)
90 it("should support indentation with spaces", function()
91 local fn
92 fn = function()
93 if true then
94 local result = 10
95 return result
96 end
97 end
98 return assert.same(fn(), 10)
99 end)
100 it("should work with consistent indentation", function()
101 local tb = {
102 a = 1,
103 b = 2,
104 nested = {
105 c = 3,
106 d = 4
107 }
108 }
109 assert.same(tb.a, 1)
110 return assert.same(tb.nested.c, 3)
111 end)
112 it("should handle semicolon with comments", function()
113 local a = 1
114 local b = 2
115 local result = a + b
116 return assert.same(result, 3)
117 end)
118 it("should work in multiline function call", function()
119 local sum
120 sum = function(a, b)
121 return a + b
122 end
123 local result = sum(5, sum(10, sum(3, 7)))
124 return assert.same(result, 25)
125 end)
126 it("should support chaining in assignment", function()
127 local obj = {
128 value = 5,
129 double = function(self)
130 return self.value * 2
131 end
132 }
133 local doubled = obj:double()
134 return assert.same(doubled, 10)
135 end)
136 it("should handle complex chaining", function()
137 local result = ("hello"):upper():sub(1, 3):lower()
138 return assert.same(result, "hel")
139 end)
140 return it("should work with backcalls and whitespace", function()
141 local readAsync
142 readAsync = function(file, callback)
143 return callback("data")
144 end
145 local process
146 process = function(data)
147 if data then
148 return true
149 end
150 end
151 local results
152 do
153 results = readAsync("data.txt", function(data)
154 return process(data)
155 end)
156 end
157 return assert.is_true(true)
158 end)
159end)