aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/using_spec.lua
blob: 5c2f357362f04cd878908eec983e3ed726ebd46a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
return describe("using", function()
	it("should prevent variable shadowing in assignment", function()
		local tmp = 100
		local i, k = 100, 50
		local process
		process = function(add)
			local tmp = tmp + add
			i = i + tmp
			k = k + tmp
		end
		process(22)
		assert.same(i, 222)
		assert.same(k, 172)
		return assert.same(tmp, 100)
	end)
	it("should handle multiple variable names", function()
		local a, b, c = 1, 2, 3
		local process
		process = function(sum)
			a = a + 1
			b = b + 2
			local c = sum + 100
		end
		process(10)
		assert.same(a, 2)
		assert.same(b, 4)
		return assert.same(c, 3)
	end)
	it("should work with nil value", function()
		local x = 1
		local fn
		fn = function(val)
			if val ~= nil then
				x = val
			end
		end
		fn(100)
		assert.same(x, 100)
		return assert.is_true(x ~= 1)
	end)
	return it("should work with function calls", function()
		local count = 0
		local fn
		fn = function(n)
			count = count + n
		end
		fn(5)
		return assert.same(count, 5)
	end)
end)