From f1be0d725735fd8dd489494b00e954a93223f722 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 23 Jan 2023 11:36:31 +0100 Subject: types: fix array unshift operations and add test coverage - Fix `ucv_array_unshift()` improperly rejecting operation on empty arrays - Fix `uc_unshift()` improperly reversing maintaining argument order - Add missing test coverage for `push()`, `pop()`, `unshift()` and `shift()` array operations. Signed-off-by: Jo-Philipp Wich --- tests/custom/03_stdlib/66_unshift | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/custom/03_stdlib/66_unshift (limited to 'tests/custom/03_stdlib/66_unshift') diff --git a/tests/custom/03_stdlib/66_unshift b/tests/custom/03_stdlib/66_unshift new file mode 100644 index 0000000..9771661 --- /dev/null +++ b/tests/custom/03_stdlib/66_unshift @@ -0,0 +1,52 @@ +The `unshift()` function places the given argument(s) at the begin of the +given array while maintaining their order. + +Returns the last added value. + +Returns `null` if the given destination argment is not an array. + +Throws a type exception if the given array is immuatable. + +-- Testcase -- +{% + let arr = []; + + printf("%.J\n", [ + // add one element + unshift(arr, 123), + + // add multiple elements + unshift(arr, 1, 2, 3), + + // add null values + unshift(arr, null, null, 4), + + // no-op + unshift(arr), + + // invalid destination + unshift({}, 1, 2, 3) + ]); + + printf("%.J\n", arr); +%} +-- End -- + +-- Expect stdout -- +[ + 123, + 3, + 4, + null, + null +] +[ + null, + null, + 4, + 1, + 2, + 3, + 123 +] +-- End -- -- cgit v1.2.3