summaryrefslogtreecommitdiffhomepage
path: root/tests/custom
diff options
context:
space:
mode:
Diffstat (limited to 'tests/custom')
-rw-r--r--tests/custom/03_stdlib/65_push52
-rw-r--r--tests/custom/03_stdlib/66_unshift52
-rw-r--r--tests/custom/03_stdlib/67_pop37
-rw-r--r--tests/custom/03_stdlib/68_shift37
4 files changed, 178 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/65_push b/tests/custom/03_stdlib/65_push
new file mode 100644
index 0000000..c6707dd
--- /dev/null
+++ b/tests/custom/03_stdlib/65_push
@@ -0,0 +1,52 @@
+The `push()` function appends the given argument(s) to the end of the given array
+while maintaining their order.
+
+Returns the last pushed 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", [
+ // push one element
+ push(arr, 123),
+
+ // push multiple elements
+ push(arr, 1, 2, 3),
+
+ // push null values
+ push(arr, null, null, 4),
+
+ // push no-op
+ push(arr),
+
+ // push with invalid destination
+ push({}, 1, 2, 3)
+ ]);
+
+ printf("%.J\n", arr);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ 123,
+ 3,
+ 4,
+ null,
+ null
+]
+[
+ 123,
+ 1,
+ 2,
+ 3,
+ null,
+ null,
+ 4
+]
+-- End --
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 --
diff --git a/tests/custom/03_stdlib/67_pop b/tests/custom/03_stdlib/67_pop
new file mode 100644
index 0000000..1af11fa
--- /dev/null
+++ b/tests/custom/03_stdlib/67_pop
@@ -0,0 +1,37 @@
+The `pop()` function removes the last element of the given source array.
+
+Returns the removed value.
+
+Returns `null` if the given source argment is not an array.
+
+Throws a type exception if the given array is immuatable.
+
+-- Testcase --
+{%
+ let arr = [ 1, null, 3 ];
+
+ printf("%.J\n", [
+ // remove one element
+ pop(arr),
+
+ // remove a null element
+ pop(arr),
+
+ // invalid source
+ pop({ test: true })
+ ]);
+
+ printf("%.J\n", arr);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ 3,
+ null,
+ null
+]
+[
+ 1
+]
+-- End --
diff --git a/tests/custom/03_stdlib/68_shift b/tests/custom/03_stdlib/68_shift
new file mode 100644
index 0000000..7b0df89
--- /dev/null
+++ b/tests/custom/03_stdlib/68_shift
@@ -0,0 +1,37 @@
+The `shift()` function removes the first element of the given source array.
+
+Returns the removed value.
+
+Returns `null` if the given source argment is not an array.
+
+Throws a type exception if the given array is immuatable.
+
+-- Testcase --
+{%
+ let arr = [ 1, null, 3 ];
+
+ printf("%.J\n", [
+ // remove one element
+ shift(arr),
+
+ // remove a null element
+ shift(arr),
+
+ // invalid source
+ shift({ test: true })
+ ]);
+
+ printf("%.J\n", arr);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ 1,
+ null,
+ null
+]
+[
+ 3
+]
+-- End --