diff options
Diffstat (limited to 'spec/inputs/test/using_spec.yue')
| -rw-r--r-- | spec/inputs/test/using_spec.yue | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/inputs/test/using_spec.yue b/spec/inputs/test/using_spec.yue new file mode 100644 index 0000000..e9ad749 --- /dev/null +++ b/spec/inputs/test/using_spec.yue | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | describe "using", -> | ||
| 2 | it "should prevent variable shadowing in assignment", -> | ||
| 3 | tmp = 100 | ||
| 4 | i, k = 100, 50 | ||
| 5 | |||
| 6 | process = (add using k, i) -> | ||
| 7 | tmp = tmp + add | ||
| 8 | i += tmp | ||
| 9 | k += tmp | ||
| 10 | |||
| 11 | process 22 | ||
| 12 | assert.same i, 222 | ||
| 13 | assert.same k, 172 | ||
| 14 | assert.same tmp, 100 | ||
| 15 | |||
| 16 | it "should handle multiple variable names", -> | ||
| 17 | a, b, c = 1, 2, 3 | ||
| 18 | |||
| 19 | process = (sum using a, b) -> | ||
| 20 | a += 1 | ||
| 21 | b += 2 | ||
| 22 | c = sum + 100 | ||
| 23 | |||
| 24 | process 10 | ||
| 25 | assert.same a, 2 | ||
| 26 | assert.same b, 4 | ||
| 27 | assert.same c, 3 | ||
| 28 | |||
| 29 | it "should work with nil value", -> | ||
| 30 | local x = 1 | ||
| 31 | |||
| 32 | fn = (val using x) -> | ||
| 33 | if val ~= nil | ||
| 34 | x = val | ||
| 35 | |||
| 36 | fn 100 | ||
| 37 | assert.same x, 100 | ||
| 38 | assert.is_true x ~= 1 | ||
| 39 | |||
| 40 | it "should work with function calls", -> | ||
| 41 | local count = 0 | ||
| 42 | |||
| 43 | fn = (n using count) -> | ||
| 44 | count += n | ||
| 45 | |||
| 46 | fn 5 | ||
| 47 | assert.same count, 5 | ||
