aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/using_spec.yue
blob: e9ad7493e04b94aba974b65ca166d33edb29342b (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
describe "using", ->
	it "should prevent variable shadowing in assignment", ->
		tmp = 100
		i, k = 100, 50

		process = (add using k, i) ->
			tmp = tmp + add
			i += tmp
			k += tmp

		process 22
		assert.same i, 222
		assert.same k, 172
		assert.same tmp, 100

	it "should handle multiple variable names", ->
		a, b, c = 1, 2, 3

		process = (sum using a, b) ->
			a += 1
			b += 2
			c = sum + 100

		process 10
		assert.same a, 2
		assert.same b, 4
		assert.same c, 3

	it "should work with nil value", ->
		local x = 1

		fn = (val using x) ->
			if val ~= nil
				x = val

		fn 100
		assert.same x, 100
		assert.is_true x ~= 1

	it "should work with function calls", ->
		local count = 0

		fn = (n using count) ->
			count += n

		fn 5
		assert.same count, 5