summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2023-05-28 20:52:10 +0200
committerJo-Philipp Wich <jo@mein.io>2023-05-30 10:11:34 +0200
commitd72eebeb168b8b350f3f9fb8cded8075464eef10 (patch)
tree84381541d89f97062744d75cfce839f278cbfeb5 /tests
parentd656d150905e8b24deb95707d675db60776c737f (diff)
lib: support object ordering in `uc_sort()`
Extend `uc_sort()` to utilize `ucv_object_sort()` in order to support reordering object keys. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-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 --
{%