diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-11-03 16:49:31 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-11-03 16:49:54 +0100 |
commit | 01deebeae5f615aff8fd8a3bb35280e60e2082ad (patch) | |
tree | 8c488925d73247ee4264969105987f1e3b703b74 /tests/00_syntax/15_function_declarations | |
parent | e8e7692f169ae00434f3e0959f104d95284d2891 (diff) |
syntax: implement ES6-like spread operator
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/00_syntax/15_function_declarations')
-rw-r--r-- | tests/00_syntax/15_function_declarations | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/00_syntax/15_function_declarations b/tests/00_syntax/15_function_declarations index 1ed6f83..f02f90a 100644 --- a/tests/00_syntax/15_function_declarations +++ b/tests/00_syntax/15_function_declarations @@ -96,3 +96,31 @@ function variadic_2(...args) { ... } ]), "\n"); %} -- End -- + + +Complementary to the "rest" argument syntax, the spread operator may be +used in function call arguments to pass arrays of values as argument list. + +-- Expect stdout -- +[ 1, 2, 3, 4, 5, 6 ] +[ 4, 5, 6, 1, 2, 3 ] +[ 1, 2, 3, 1, 2, 3 ] +[ 1, 2, 3 ] +-- End -- + +-- Testcase -- +{% + arr = [ 1, 2, 3 ]; + + function test(...args) { + return args; + } + + print(join("\n", [ + test(...arr, 4, 5, 6), + test(4, 5, 6, ...arr), + test(...arr, ...arr), + test(...arr) + ]), "\n"); +%} +-- End -- |