aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/using_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/test/using_spec.lua')
-rw-r--r--spec/outputs/test/using_spec.lua50
1 files changed, 50 insertions, 0 deletions
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)