summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib/50_uniq
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-29 23:31:16 +0100
committerJo-Philipp Wich <jo@mein.io>2022-02-03 17:22:43 +0100
commit7edad5cefa0f065aa83dffd2d7830aeaf9f38662 (patch)
tree86b727f434302ffb28cb59278243517f9765e170 /tests/custom/03_stdlib/50_uniq
parentd5003fde57eab19588da7bfdbaefe93d47435eb6 (diff)
tests: add functional tests for builtin functions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib/50_uniq')
-rw-r--r--tests/custom/03_stdlib/50_uniq66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/50_uniq b/tests/custom/03_stdlib/50_uniq
new file mode 100644
index 0000000..6e13077
--- /dev/null
+++ b/tests/custom/03_stdlib/50_uniq
@@ -0,0 +1,66 @@
+The `uniq()` function extracts the unique set of all values within the
+given input array, maintaining the original order.
+
+Returns an array containing all unique items of the input array.
+
+Returns `null` if the input is not an array value.
+
+-- Testcase --
+{%
+ let o1 = { an: "object" };
+ let o2 = { an: "object" }; // same but not identical
+
+ let a1 = [ 1, 2, 3 ];
+ let a2 = [ 1, 2, 3 ]; // same but not identical
+
+ printf("%.J\n", [
+ // strict comparison is used, 0 and "0" are not unique
+ uniq([ 0, 1, 2, 0, "0", 2, 3, "4", 4 ]),
+
+ // despite NaN != NaN, two NaN values are not unique
+ uniq([ NaN, NaN ]),
+
+ // only identical objects are filtered, not equivalent ones
+ uniq([ o1, o1, o2, a1, a1, a2 ]),
+
+ // invalid input yields `null`
+ uniq(true)
+ ]);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ [
+ 0,
+ 1,
+ 2,
+ "0",
+ 3,
+ "4",
+ 4
+ ],
+ [
+ "NaN"
+ ],
+ [
+ {
+ "an": "object"
+ },
+ {
+ "an": "object"
+ },
+ [
+ 1,
+ 2,
+ 3
+ ],
+ [
+ 1,
+ 2,
+ 3
+ ]
+ ],
+ null
+]
+-- End --