Modul:Collation/testcases

Z Wikipedie, otevřené encyklopedie
Skočit na navigaci Skočit na vyhledávání
-- Testy pro [[Modul:Collation]]. Spouští se v diskusi.
local p = require('Modul:UnitTests')
local collation = require('Modul:Collation')

function p:test_compare()
	self:equals('compare(): -1 if a < b', collation.compare('a', 'b'), -1)
	self:equals('compare(): 0 if left = right', collation.compare('a', mw.ustring.char(0x61)), 0)
	self:equals('compare(): 1 if b > a', collation.compare('b', 'a'), 1)

	self:equals('compare(): -1 if aa < ab', collation.compare('aa', 'ab'), -1)
	self:equals('compare(): -1 if ab < aba', collation.compare('ab', 'aba'), -1)
end


function p:test_sortCompare()
	self:equals('sortCompare(): true if a < b', collation.sortCompare('a', 'b'), true)
	self:equals('sortCompare(): false if a >= a', collation.sortCompare('a', mw.ustring.char(0x61)), false)
	self:equals('sortCompare(): false if b >= a', collation.sortCompare('b', 'a'), false)

	self:equals('sortCompare(): true if aa < ab', collation.sortCompare('aa', 'ab'), true)
	self:equals('sortCompare(): true if ab < aba', collation.sortCompare('ab', 'aba'), true)
end

function p:test_CSN_97_6030()
	local tbl1 = {
        "sálá",
        "ta",
        "padá",
        "satira",
        "sál",
        "šat",
        "sílí",
        "šála",
        "si nese",
        "si lehá",
        "säla",
        "sála",
	}
	local tbl1_sorted = {
        "padá",
        "sál",
        "sála",
        "sálá",
        "säla",
        "satira",
        "si lehá",
        "si nese",
        "sílí",
        "šála",
        "šat",
        "ta",
	}
	table.sort(tbl1, collation.sortCompare)
	self:equals_deep('ČSN 97 6030: Implementovaná část', tbl1, tbl1_sorted)

	local tbl2 = {
		"Citroën",
		"Citrol",
	}
	local tbl2_sorted = {
		"Citroën",
		"Citrol",
	}
	table.sort(tbl2, collation.sortCompare)
	self:equals_deep('ČSN 97 6030: Neimplementované znaky', tbl2, tbl2_sorted)
end

return p