Module:Sandbox/Batternut/Ordinal/testcases

-- Unit tests for Module:Sandbox/Batternut/Ordinal. Click talk page to run tests. local ut = require('Module:UnitTests') local o = require('Module:Sandbox/Batternut/Ordinal') local w = require('Module:Wikidata')

function ut:dont_test_Wikidata local langcode = 'en'

self:equals ('1', w.makeOrdinal(1, langcode), '1st') self:equals ('2', w.makeOrdinal(2, langcode), '2nd') self:equals ('3', w.makeOrdinal(3, langcode), '3rd') self:equals ('4', w.makeOrdinal(4, langcode), '4th') end

function ut:test_English -- 	langcode = mw.message.getDefaultLanguage.code local langcode = 'en'

self:equals ('1', o.makeOrdinal(1, langcode), '1st') self:equals ('2', o.makeOrdinal(2, langcode), '2nd') self:equals ('3', o.makeOrdinal(3, langcode), '3rd') self:equals ('4', o.makeOrdinal(4, langcode), '4th') self:equals ('10', o.makeOrdinal(10, langcode), '10th') self:equals ('11', o.makeOrdinal(11, langcode), '11th') self:equals ('12', o.makeOrdinal(12, langcode), '12th') self:equals ('13', o.makeOrdinal(13, langcode), '13th') self:equals ('14', o.makeOrdinal(14, langcode), '14th') self:equals ('20', o.makeOrdinal(20, langcode), '20th') self:equals ('21', o.makeOrdinal(21, langcode), '21st') self:equals ('22', o.makeOrdinal(22, langcode), '22nd') self:equals ('23', o.makeOrdinal(23, langcode), '23rd') self:equals ('24', o.makeOrdinal(24, langcode), '24th') end

function ut:test_French -- 	langcode = mw.message.getDefaultLanguage.code local langcode = 'fr' self:equals ('1', o.makeOrdinal(1, langcode), '1er') self:equals ('2', o.makeOrdinal(2, langcode), '2e') self:equals ('3', o.makeOrdinal(3, langcode), '3e')

self:equals ('10', o.makeOrdinal(10, langcode), '10e') self:equals ('20', o.makeOrdinal(20, langcode), '20e') self:equals ('21', o.makeOrdinal(21, langcode), '21e') end

function ut:test_Default -- 	langcode = mw.message.getDefaultLanguage.code local langcode = nil self:equals ('1', o.makeOrdinal(1, langcode), '1.') self:equals ('2', o.makeOrdinal(2, langcode), '2.') self:equals ('3', o.makeOrdinal(3, langcode), '3.')

self:equals ('10', o.makeOrdinal(10, langcode), '10.') self:equals ('20', o.makeOrdinal(20, langcode), '20.') end

function ut:test_Prefered_language self:equals ('English?', mw.message.getDefaultLanguage.code, 'en') end

return ut