diff options
| author | A2va <[email protected]> | 2023-09-30 16:46:03 +0200 |
|---|---|---|
| committer | A2va <[email protected]> | 2023-09-30 16:46:03 +0200 |
| commit | b637e0acc32faeeda669e135c546999c4a8e0c17 (patch) | |
| tree | 7752e08841d9a7b376c60b342164473c93cf7364 /tests/modules/table/test.lua | |
| parent | 082c0d445eb93734bcf2f010b4c8874f8fcc2f55 (diff) | |
Sort keys by callback function
Diffstat (limited to 'tests/modules/table/test.lua')
| -rw-r--r-- | tests/modules/table/test.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/modules/table/test.lua b/tests/modules/table/test.lua index 007782cf4..297832575 100644 --- a/tests/modules/table/test.lua +++ b/tests/modules/table/test.lua @@ -29,3 +29,18 @@ function test_unwrap(t) local a = table.wrap_lock({1}) t:are_equal(table.unwrap(a), a) end + +function test_orderkeys(t) + -- sort by modulo 2 then from the smallest to largest + local f = function(a, b) + if a % 2 == 0 then + return true + elseif b % 2 == 0 then + return false + end + return a < b + end + + t:are_equal(table.orderkeys({[2] = 2, [1] = 1, [4] = 4, [3] = 3}, f), {2, 4, 1, 3}) + t:are_equal(table.orderkeys({[1] = 1, [2] = 2, [3] = 3, [4] = 4}), {1, 2 , 3, 4}) +end |
