Documentația acestui modul poate fi creată la Modul:Formatnum/testcases/doc

local p = require('Modul:UnitTests')
local f = require('Modul:Formatnum')
function p:test_stripSeparators()
	self:equals("No separator", f._stripSeparators("123456789"), 123456789)
	self:equals("One comma", f._stripSeparators("123456,789"), 123456.789)
	self:equals("Comma only", f._stripSeparators("123,456,789"), 123456789)
	self:equals("One dot", f._stripSeparators("123456.789"), 123456.789)
	self:equals("One dot, one comma English", f._stripSeparators("123,456.789"), 123456.789)
	self:equals("One dot, one comma Romanian", f._stripSeparators("123.456,789"), 123456.789)
	self:equals("One dot, 2 commas", f._stripSeparators("123,456,789.012"), 123456789.012)
	self:equals("Dot only", f._stripSeparators("123.456.789"), 123456789)
	self:equals("2 dots, 1 comma", f._stripSeparators("123.456.789,012"), 123456789.012)
	self:equals("2 dots, 2 commas", f._stripSeparators("123.456.789,012,345"), nil)
end

function p:test_forceStripSeparators()
	self:equals("One comma, thousands", f._stripSeparators("1,234"), 1.234)
	self:equals("One comma, decimal", f._stripSeparators("123456,789"), 123456.789)
	self:equals("One comma, confusing", f._stripSeparators("123,456"), 123.456)
	self:equals("One dot, thousands", f._stripSeparators("1.234"), 1.234)
	self:equals("One dot, decimal", f._stripSeparators("123456.789"), 123456.789)
	self:equals("One dot, confusing", f._stripSeparators("123.456"), 123.456)
end

function p:test_invokeStripSeparators()
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123456789}}", "123456789")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123456,789}}", "123456.789")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123,456,789}}", "123456789")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123456.789}}", "123456.789")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123,456.789}}", "123456.789")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123.456,789}}", "123456.789")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123,456,789.012}}", "123456789.012")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123.456.789}}", "123456789")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123.456.789,012}}", "123456789.012")
	self:preprocess_equals("{{#invoke:Formatnum|stripSeparators|123.456.789,012,345}}", "")
end

function p:test_1_English_basic()
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|0|en}}', '0')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|-123|en}}', '−123')
end

function p:test_2_unnecessary_signs()
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|-0|en}}', '0')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|+123|en}}', '123')
end

function p:test_3_non_numbers_preserved()
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|12:34:45|en}}', '12:34:45')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|12 h 34|fr}}', '12 h 34')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|12:34:45|th}}', '12:34:45')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|12:34:45.00|en}}', '12:34:45.00')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|12°34′45.00″|en}}', '12°34′45.00″')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|1234 locuitori|ro}}', '1234 locuitori')
end

function p:test_5_English_bad_parameters()
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|200.1|en|prec=3,5}}', '200.1')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|200.1|en|prec=a}}', '200.1')
end

function p:test_6_decimal_separator()
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|.12345|en}}', '0.12345')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|.12345|ro}}', '0,12345')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|123.45|en}}', '123.45')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|123.45|ro}}', '123,45')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|123.|en}}', '123')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|123.|ro}}', '123')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|123.00|en}}', '123')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|123.00|ro}}', '123')
end

function p:test_7_no_grouping_separators()
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|en|sep=1}}', '100000')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|fr|sep=1}}', '100000')
end

function p:test_8_HTML_entity_or_native_UTF8()
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|12345|en}}', '12,345')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|12345|ro}}', '12.345')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|12345|fr}}', '12\194\160345') -- "\194\160" in Lua litterals is NBSP (U+00A0) encoded in UTF-8 (0xC2,0xA0)
end

function p:test_9_large_numbers()
	self:preprocess_equals('{{#invoke:Formatnum|formatNum|234,907,967,154,120}}', '2,3490796715412 × 10<sup>14</sup>')
	self:preprocess_equals('{{#invoke:Formatnum|formatNum|{{#expr:1/234907967154122528}}}}', '4,2569863087866 × 10<sup>-18</sup>')
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('{{#invoke:Formatnum|formatNum|100000||sep=1}}', '100000') -- unspecified Wikimedia default
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|aa|sep=1}}', '100000') -- Afar
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|qq|sep=1}}', '100000') -- Private-use
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|qqa|sep=1}}', '100000') -- Private-use
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|mul|sep=1}}', '100000') -- Multilingual
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|und|sep=1}}', '100000') -- Undetermined
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|root|sep=1}}', '100000') -- CLDR default
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|user|sep=1}}', '100000')
    self:preprocess_equals('{{#invoke:Formatnum|formatNum|100000|invalid|sep=1}}', '100000')
end

function p:test_underflow()
	self:preprocess_equals('{{#invoke:Formatnum|formatNum|0.0000001|ro}}', '1 × 10<sup>-7</sup>')
	self:preprocess_equals('{{#invoke:Formatnum|formatNum|0.000001|ro}}', '1 × 10<sup>-6</sup>')
	self:preprocess_equals('{{#invoke:Formatnum|formatNum|0.00001|ro}}', '1 × 10<sup>-5</sup>')
	self:preprocess_equals('{{#invoke:Formatnum|formatNum|0.0001|ro}}', '0,0001')
	self:preprocess_equals('{{#invoke:Formatnum|formatNum|0.001|ro}}', '0,001')
	self:preprocess_equals('{{#invoke:Formatnum|formatNum|0.01|ro}}', '0,01')
end
return p