summaryrefslogtreecommitdiffhomepage
path: root/tests/custom
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2023-06-06 10:13:53 +0200
committerGitHub <noreply@github.com>2023-06-06 10:13:53 +0200
commitc7d84aae09691a99ae3db427c0b2463732ef84f4 (patch)
tree2b8a04d11ac4ecca6fad53dac87b5a2259df11a4 /tests/custom
parent3ffb046c59a690eb102b23f4539afd956f7e72d7 (diff)
parentd72eebeb168b8b350f3f9fb8cded8075464eef10 (diff)
Merge pull request #153 from jow-/lib-sort-object-support
lib: support object ordering in `uc_sort()`
Diffstat (limited to 'tests/custom')
-rw-r--r--tests/custom/03_stdlib/16_sort16
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/custom/03_stdlib/16_sort b/tests/custom/03_stdlib/16_sort
index ac4a0e1..14d0e12 100644
--- a/tests/custom/03_stdlib/16_sort
+++ b/tests/custom/03_stdlib/16_sort
@@ -40,7 +40,16 @@ Returns `null` if the given input array value is not an array.
return 1;
return 0;
- })
+ }),
+
+ // default lexical object key sort
+ sort({ qrx: 1, foo: 2, abc: 3 }),
+
+ // object sort with custom callback (by value)
+ sort({ a: 5, b: 3, c: 2, d: 4, e: 1 }, (k1, k2, v1, v2) => v1 - v2),
+
+ // object sort with custom callback (by key length)
+ sort({ "Bean": true, "Orange": true, "Apple": true }, (k1, k2) => length(k1) - length(k2))
]), "\n");
%}
-- End --
@@ -51,6 +60,9 @@ Returns `null` if the given input array value is not an array.
[ 1, "2b", false, null, true ]
[ "pear", "apple", "banana", "grapefruit" ]
[ 1, 2, 4, 9, "a", "b", "q", "x" ]
+{ "abc": 3, "foo": 2, "qrx": 1 }
+{ "e": 1, "c": 2, "b": 3, "d": 4, "a": 5 }
+{ "Bean": true, "Apple": true, "Orange": true }
-- End --
@@ -73,7 +85,7 @@ In line 2, byte 34:
-- End --
-Supplying an invalid array will yield `null`.
+Supplying a non-array, non-object value will yield `null`.
-- Testcase --
{%