From a8087a9dbb8b24b451bfaa5d31e07e9b5574226d Mon Sep 17 00:00:00 2001 From: Daniel Csillag Date: Tue, 11 Apr 2023 07:48:17 -0300 Subject: Array sorting by key (#584) --- tests/typ/compiler/array.typ | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/typ/compiler/array.typ') diff --git a/tests/typ/compiler/array.typ b/tests/typ/compiler/array.typ index b9e5517e..97b5da52 100644 --- a/tests/typ/compiler/array.typ +++ b/tests/typ/compiler/array.typ @@ -193,9 +193,18 @@ --- // Test the `sorted` method. #test(().sorted(), ()) +#test(().sorted(key: x => x), ()) #test(((true, false) * 10).sorted(), (false,) * 10 + (true,) * 10) #test(("it", "the", "hi", "text").sorted(), ("hi", "it", "text", "the")) +#test(("I", "the", "hi", "text").sorted(key: x => x), ("I", "hi", "text", "the")) +#test(("I", "the", "hi", "text").sorted(key: x => x.len()), ("I", "hi", "the", "text")) #test((2, 1, 3, 10, 5, 8, 6, -7, 2).sorted(), (-7, 1, 2, 2, 3, 5, 6, 8, 10)) +#test((2, 1, 3, -10, -5, 8, 6, -7, 2).sorted(key: x => x), (-10, -7, -5, 1, 2, 2, 3, 6, 8)) +#test((2, 1, 3, -10, -5, 8, 6, -7, 2).sorted(key: x => x * x), (1, 2, 2, 3, -5, 6, -7, 8, -10)) + +--- +// Error: 32-37 cannot divide by zero +#(1, 2, 0, 3).sorted(key: x => 5 / x) --- // Error: 2-26 cannot order content and content -- cgit v1.2.3