diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-28 18:43:14 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-28 18:43:14 +0800 |
| commit | dd64edd58fe25ec74ae5958128cf3f74b0692f3b (patch) | |
| tree | 0f2de1df55897e2713977c5a53936757e14b477a /spec/inputs/test/functions_advanced_spec.yue | |
| parent | 7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (diff) | |
| download | yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.gz yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.bz2 yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.zip | |
Fixed compiler issues and added 800+ test cases.
Diffstat (limited to 'spec/inputs/test/functions_advanced_spec.yue')
| -rw-r--r-- | spec/inputs/test/functions_advanced_spec.yue | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/spec/inputs/test/functions_advanced_spec.yue b/spec/inputs/test/functions_advanced_spec.yue index d0e0cf5..32f0718 100644 --- a/spec/inputs/test/functions_advanced_spec.yue +++ b/spec/inputs/test/functions_advanced_spec.yue | |||
| @@ -19,32 +19,32 @@ describe "advanced functions", -> | |||
| 19 | x + y | 19 | x + y |
| 20 | 20 | ||
| 21 | assert.same fn!, 1200 | 21 | assert.same fn!, 1200 |
| 22 | assert.same fn(50), 1150 | 22 | assert.same fn(50), 1100 |
| 23 | 23 | ||
| 24 | it "should work with multi-line arguments", -> | 24 | it "should work with multi-line arguments", -> |
| 25 | my_func = (a, b, c, d, e, f) -> a + b + c + d + e + f | 25 | my_func = (a, b, c, d, e, f) -> a + b + c + d + e + f |
| 26 | result = my_func 5, 4, 3, | 26 | result = my_func 5, 4, 3, |
| 27 | 8, 9, 10 | 27 | 8, 9, 10 |
| 28 | assert.same result, 39 | 28 | assert.same result, 39 |
| 29 | 29 | ||
| 30 | it "should support nested function calls", -> | 30 | it "should support nested function calls", -> |
| 31 | another_func = (a, b, c, d, e, f) -> a + b + c + d + e + f | ||
| 32 | my_func = (a, b, c, d, e, f, g) -> a + b + c + d + e + f + g | ||
| 33 | |||
| 31 | result = my_func 5, 6, 7, | 34 | result = my_func 5, 6, 7, |
| 32 | 6, another_func 6, 7, 8, | 35 | 6, another_func 6, 7, 8, |
| 33 | 9, 1, 2, | 36 | 9, 1, 2, |
| 34 | 5, 4 | 37 | 5, 4 |
| 35 | 38 | ||
| 36 | another_func = (a, b, c, d, e, f) -> a + b + c + d + e + f | 39 | assert.same result, 66 |
| 37 | my_func = (a, b, c, d, e, f) -> a + b + c + d + e + f | ||
| 38 | |||
| 39 | assert.same result, 52 | ||
| 40 | 40 | ||
| 41 | it "should handle implicit return", -> | 41 | it "should handle implicit return", -> |
| 42 | sum = (x, y) -> x + y | 42 | sum = (x, y) -> x + y |
| 43 | assert.same sum 10, 20, 30 | 43 | assert.same sum(10, 20), 30 |
| 44 | 44 | ||
| 45 | it "should work with explicit return", -> | 45 | it "should work with explicit return", -> |
| 46 | difference = (x, y) -> return x - y | 46 | difference = (x, y) -> return x - y |
| 47 | assert.same difference 20, 10, 10 | 47 | assert.same difference(20, 10), 10 |
| 48 | 48 | ||
| 49 | it "should support multiple return values", -> | 49 | it "should support multiple return values", -> |
| 50 | mystery = (x, y) -> x + y, x - y | 50 | mystery = (x, y) -> x + y, x - y |
| @@ -85,7 +85,7 @@ describe "advanced functions", -> | |||
| 85 | assert.same fn(1, 2, 3), 3 | 85 | assert.same fn(1, 2, 3), 3 |
| 86 | 86 | ||
| 87 | it "should support prefixed return", -> | 87 | it "should support prefixed return", -> |
| 88 | findValue: "not found" -> | 88 | findValue = (): "not found" -> |
| 89 | items = [1, 2, 3] | 89 | items = [1, 2, 3] |
| 90 | for item in *items | 90 | for item in *items |
| 91 | if item == 5 | 91 | if item == 5 |
| @@ -155,4 +155,4 @@ describe "advanced functions", -> | |||
| 155 | -> 0 | 155 | -> 0 |
| 156 | 156 | ||
| 157 | add = get_operation "add" | 157 | add = get_operation "add" |
| 158 | assert.same add 5, 3, 8 | 158 | assert.same add(5, 3), 8 |
