aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/using_spec.yue
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-30 18:16:45 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-30 18:16:45 +0800
commit8c3d786157ec7fef3072feac55c2d5450800568b (patch)
tree6c44a85e02abe74e6c3ccc4d7393ba8784c49ce7 /spec/inputs/test/using_spec.yue
parent220a10d0df3341b2bbb0beaee4f90d6480e7ae38 (diff)
downloadyuescript-8c3d786157ec7fef3072feac55c2d5450800568b.tar.gz
yuescript-8c3d786157ec7fef3072feac55c2d5450800568b.tar.bz2
yuescript-8c3d786157ec7fef3072feac55c2d5450800568b.zip
Added more tests.HEADmain
Diffstat (limited to 'spec/inputs/test/using_spec.yue')
-rw-r--r--spec/inputs/test/using_spec.yue47
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 @@
1describe "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