Fix sorting with custom comparator, and add unit tests to regress

This commit is contained in:
James Roseborough
2008-04-03 03:58:15 +00:00
parent faaee456ad
commit 35ed9dca3c
4 changed files with 33 additions and 2 deletions

27
src/test/res/sort.lua Normal file
View File

@@ -0,0 +1,27 @@
-- concat
print( '-- sort tests' )
local function tryall(cmp)
local function try(t)
print( table.concat(t,'-') )
if pcall( table.sort, t, cmp ) then
print( table.concat(t,'-') )
else
print( 'sort failed' )
end
end
try{ 2, 4, 6, 8, 1, 3, 5, 7 }
try{ 333, 222, 111 }
try{ "www", "xxx", "yyy", "aaa", "bbb", "ccc" }
try{ 21, 23, "25", 27, 22, "24", 26, 28 }
end
local function comparator(a,b)
return tonumber(a)<tonumber(b)
end
tryall()
tryall(comparator)