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/13_object_literals | |
parent | e8e7692f169ae00434f3e0959f104d95284d2891 (diff) |
syntax: implement ES6-like spread operator
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/00_syntax/13_object_literals')
-rw-r--r-- | tests/00_syntax/13_object_literals | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/00_syntax/13_object_literals b/tests/00_syntax/13_object_literals index 4b4f934..60c9f32 100644 --- a/tests/00_syntax/13_object_literals +++ b/tests/00_syntax/13_object_literals @@ -49,3 +49,44 @@ either JSON or JavaScript notation. print(third_obj, "\n"); print(nested_obj, "\n"); -- End -- + + +Additionally, utpl implements ES6-like spread operators to allow shallow copying +of object properties into other objects. + +-- Expect stdout -- +{ "foo": true, "bar": false } +{ "foo": true, "bar": false, "baz": 123, "qrx": 456 } +{ "foo": false, "bar": true, "baz": 123, "qrx": 456 } +{ "foo": true, "bar": false } +{ "foo": true, "bar": false, "level2": { "baz": 123, "qrx": 456 } } +{ "foo": true, "bar": false, "0": 7, "1": 8, "2": 9 } +-- End -- + +-- Testcase -- +{% + o1 = { foo: true, bar: false }; + o2 = { baz: 123, qrx: 456 }; + arr = [7, 8, 9]; + + print(join("\n", [ + // copying one object into another + { ...o1 }, + + // combining two objects + { ...o1, ...o2 }, + + // copying object and override properties + { ...o1, ...o2, foo: false, bar: true }, + + // default properties overwritten by spread operator + { foo: 123, bar: 456, ...o1 }, + + // nested spread operators + { ...o1, level2: { ...o2 } }, + + // merging array into objects + { ...o1, ...arr } + ]), "\n"); +%} +-- End -- |