Module:Formatnum/testcases

-- Unit tests for Module:Formatnum. Click talk page to run tests. local p = require('Module:UnitTests')

local function err(msg) -- Generates wikitext error messages. return mw.ustring.format(' Formatting error: %s ', msg) end

function p:test_1_English_basic self:preprocess_equals('', '0') self:preprocess_equals('', '-123') end

function p:test_2_unnecessary_signs self:preprocess_equals('', '0') self:preprocess_equals('', '123') end

function p:test_3_non_numbers_preserved self:preprocess_equals('', '12:34:45') self:preprocess_equals('', '12 h 34') self:preprocess_equals('', '12:34:45') self:preprocess_equals('', '12:34:45.00') self:preprocess_equals('', '12°34′45.00″') self:preprocess_equals('', 'some words...') end

function p:test_4_English_precision_rounding self:preprocess_equals('', '100.0') self:preprocess_equals('', '100.0') self:preprocess_equals('', '100.01') self:preprocess_equals('', '100.010') self:preprocess_equals('', '100.01') end

function p:test_5_English_bad_parameters self:preprocess_equals('', '.10,00') self:preprocess_equals('', '.10,00') self:preprocess_equals('', '100,0.') self:preprocess_equals('', '100,0.') self:preprocess_equals('', '100.01') self:preprocess_equals('', '200.100') self:preprocess_equals('', '200.1') self:preprocess_equals('', '200.1') end

function p:test_6_decimal_separator self:preprocess_equals('', '0.12345') self:preprocess_equals('', '0,12345') self:preprocess_equals('', '123.45') self:preprocess_equals('', '123,45') self:preprocess_equals('', '123') self:preprocess_equals('', '123') self:preprocess_equals('', '123') self:preprocess_equals('', '123') self:preprocess_equals('', '1.001') self:preprocess_equals('', '1001') self:preprocess_equals('', '1,001') end

function p:test_7_no_grouping_separators self:preprocess_equals('', '100000') self:preprocess_equals('', '100000') end

function p:test_8_HTML_entity_or_native_UTF8 self:preprocess_equals('', '12,345') self:preprocess_equals('', '12\194\160345') -- "\194\160" in Lua litterals is NBSP (U+00A0) encoded in UTF-8 (0xC2,0xA0) self:preprocess_equals('', '12,345') self:preprocess_equals('', '12\194\160345') self:preprocess_equals('', '12\194\160345') self:preprocess_equals('', '12\194\160345') self:preprocess_equals('', '12\194\160345') self:preprocess_equals('', '12\194\160345') end

function p:test_9_grouping_separators self:preprocess_equals('', '1,234,567,890') self:preprocess_equals('', '1.234.567.890') self:preprocess_equals('', '1.234.567.890') self:preprocess_equals('', '1,234,567,890') self:preprocess_equals('', '᠑,᠒᠓᠔,᠕᠖᠗,᠘᠙᠐') self:preprocess_equals('', '۱,۲۳۴,۵۶۷,۸۹۰') self:preprocess_equals('', '۱,۲۳۴,۵۶۷,۸۹۰') self:preprocess_equals('', '۱,۲۳۴,۵۶۷,۸۹۰') self:preprocess_equals('', '१,२३,४५,६७,८९०') self:preprocess_equals('', '১,২৩,৪৫,৬৭,৮৯০') self:preprocess_equals('', '1,23,45,67,890') self:preprocess_equals('', '౧,౨౩,౪౫,౬౭,౮౯౦') self:preprocess_equals('', '೧,೨೩,೪೫,೬೭,೮೯೦ ') self:preprocess_equals('', '୧,୨୩,୪୫,୬୭,୮୯୦') self:preprocess_equals('', '1,23,45,67,890') self:preprocess_equals('', '1,23,45,67,890') self:preprocess_equals('', '༡,༢༣༤,༥༦༧,༨༩༠') self:preprocess_equals('', '๑,๒๓๔,๕๖๗,๘๙๐') self:preprocess_equals('', '1,234,567,890') self:preprocess_equals('', '໑,໒໓໔,໕໖໗,໘໙໐ ') end

function p:test_Error_more_than_20_languages self:preprocess_equals('', '100000') self:preprocess_equals('', '100000') end

function p:test_Unsupported_languages_using_user_default_language_instead_may_fail -- these may fail depending on supported language of the user if it uses non-ASCII digits self:preprocess_equals('', '100000') -- unspecified Wikimedia default self:preprocess_equals('', '100000') -- Afar self:preprocess_equals('', '100000') -- Private-use self:preprocess_equals('', '100000') -- Private-use self:preprocess_equals('', '100000') -- Multilingual self:preprocess_equals('', '100000') -- Undetermined self:preprocess_equals('', '100000') -- CLDR default self:preprocess_equals('', '100000') self:preprocess_equals('', '100000') end

return p