local t = require('Modul:UnitTests')
local mut = require('Modul:sort')
function t:test01_basic()
self:equals('s.getSortKey("sv","abc")', mut.getSortKey("sv","abc"), "abc")
self:equals('s.getSortKey("sv","a b c")', mut.getSortKey("sv","a b c"), "abc")
self:equals('s.getSortKey("fr","TV")', mut.getSortKey("fr","TV"), "tv")
end
function t:test02_diacritics()
self:equals('s.getSortKey("sv","åra")', mut.getSortKey("sv","åra"), "z~ra")
self:equals('s.getSortKey("en","åra")', mut.getSortKey("en","åra"), "ara")
self:equals('s.getSortKey("sv","Åre")', mut.getSortKey("sv","Åre"), "z~re")
self:equals('s.getSortKey("fr","Åre")', mut.getSortKey("fr","Åre"), "are")
self:equals('s.getSortKey("","éüåäö")', mut.getSortKey("","éüåäö"), "euaao")
self:equals('s.getSortKey("xyz","éüåäö")', mut.getSortKey("xyz","éüåäö"), "euaao")
end
function t:test03_special_characters()
self:equals('s.getSortKey("de","a.,-b")', mut.getSortKey("de","a.,-b"), "ab")
self:equals('s.getSortKey("","a.,-b")', mut.getSortKey("","a.,-b"), "ab")
self:equals('s.getSortKey("xx","a.,-b")', mut.getSortKey("xx","a.,-b"), "ab")
self:equals('s.getSortKey("xx","a&b")', mut.getSortKey("xx","a&b"), "ab")
end
function t:test04_missing_pagename()
self:equals('s.getSortKey("sv")', mut.getSortKey("sv"), "")
self:equals('s.getSortKey("sv","")', mut.getSortKey("sv",""), "")
end
function t:test05_bad_language_code()
self:equals('s.getSortKey(nil,"é.,-b")', mut.getSortKey(nil,"é.,-b"), "eb")
self:equals('s.getSortKey("","é.,-b")', mut.getSortKey(nil,"é.,-b"), "eb")
self:equals('s.getSortKey("xx","é.,-b")', mut.getSortKey(nil,"é.,-b"), "eb")
self:equals('s.getSortKey("xyz","é.,-b")', mut.getSortKey(nil,"é.,-b"), "eb")
end
function t:test06_numbers_basic()
self:equals('s.getSortKey("sv","33")', mut.getSortKey("sv","33"), "::33")
self:equals('s.getSortKey("sv","ab33cd")', mut.getSortKey("sv","ab33cd"), "ab::33cd")
end
function t:test07_numbers_with_special_characters()
self:equals('s.getSortKey("sv","1,2-etandiol")', mut.getSortKey("sv","1,2-etandiol"), "::12etandiol")
self:equals('s.getSortKey("sv","1,2,3-propantriol")', mut.getSortKey("sv","1,2,3-propantriol"), ":::123propantriol")
end
function t:test08_numbers_multiple_occurances()
self:equals('s.getSortKey("sv","ab33cd9988ef")', mut.getSortKey("sv","ab33cd9988ef"), "ab::33cd::::9988ef")
self:equals('s.getSortKey("sv","ab0033cd09900ef")', mut.getSortKey("sv","ab0033cd09900ef"), "ab::33cd::::9900ef")
end
function t:test09_dont_mess_up_non_latin()
self:equals('s.getSortKey("zh", "中世紀")', mut.getSortKey("zh", "中世紀"), "中世紀")
end
return t