summaryrefslogtreecommitdiff
path: root/tests/modules/table/test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/modules/table/test.lua')
-rw-r--r--tests/modules/table/test.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/modules/table/test.lua b/tests/modules/table/test.lua
index 007782cf4..2b586e7a4 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 and b % 2 ~= 0 then
+ return true
+ elseif b % 2 == 0 and a % 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