मॉड्यूल:time/testcases
दिखावट
"इस मॉड्यूल हेतु प्रलेख मॉड्यूल:time/testcases/doc पर बनाया जा सकता है"
local export = {}
local schemata
local function code_tag(text, class)
if class then
return '<code class="' .. class .. '">' .. mw.text.nowiki(text) .. '</code>'
else
return "<code>" .. mw.text.nowiki(text) .. "</code>"
end
end
local function iterate_tsv(tsv)
local rows = tsv:gmatch "[^\n]+"
return function()
local row = rows()
if row then
local columns = {}
local prev_pos = 1
for start_pos, column, tab, end_pos in row:gmatch "()([^\t]+)(\t?)()" do
if not (start_pos == prev_pos and (tab == "") == (end_pos == #row + 1)) then
error("incorrect format in " .. row)
end
table.insert(columns, column)
prev_pos = end_pos
end
return unpack(columns)
end
end
end
local remove_links = require "Module:links".remove_links
function export.test_date_formatting(frame)
local module_name = frame.args.module
local quote_impl = require(module_name and "Module:" .. module_name or "Module:time").quote_impl
local function format_date(date)
return quote_impl { date = date }
end
local output = require "Module:array"()
output:insert [[
{| class="wikitable"
! input !! occurrences !! output !! expected !! error
]]
local counts = { [true] = 0, [false] = 0 }
for schema, count, date, expected in iterate_tsv(schemata) do
count = tonumber(count)
if not schema then
error("Line didn't match pattern: " .. line)
end
local ok, formatted = pcall(function() return format_date(date):gsub("'''", "") end)
local success = ok and formatted == expected
counts[success] = counts[success] + 1
if ok then
if formatted ~= expected then
output:insert "|-"
output:insert("| " .. code_tag(date) .. " || " .. count .. " || "
.. code_tag(formatted) .. " || " .. code_tag(expected) .. " ||")
end
else
output:insert "|-"
output:insert("| " .. code_tag(date) .. " || " .. count
.. " || || " .. code_tag(expected) .. " || "
.. code_tag(remove_links(formatted), "error"))
end
end
output:insert "|}"
output:insert(1, counts[true] .. "/" .. (counts[true] + counts[false]) .. " successes")
return output:concat "\n"
end
schemata = [[
<u><l> <d2>, <d4> 19297 September 14, 2014 2014 September 14
<u><l> <d1>, <d4> 8324 March 9, 2008 2008 March 9
<d4>-<d2>-<d2> 6293 1997-07-14 1997 July 14
<d2> <u><l> <d4> 4526 15 October 2002 2002 October 15
<u><l> <d2> <d4> 2866 Oct 18 2011 2011 October 18
<d1> <u><l> <d4> 1914 6 March 1992 1992 March 6
<u><l> <d1> <d4> 1252 Apr 7 2003 2003 April 7
<u><l> <d4> 1065 January 1911 1911 January
<d4>-<d2> 368 1843-06 1843 June
<d4> <u><l> <d2> 206 1939 December 15 1939 December 15
<d4>-<d1>-<d2> 190 2018-4-22 2018 April 22
<d2>-<d2>-<d4> 180 10-05-2003 2003 May 10
<u><l>. <d2>, <d4> 179 Aug. 13, 2015 2015 August 13
<d4> <u><l> <d1> 173 2020 January 2 2020 January 2
<u><l>. <d1>, <d4> 102 Dec. 2, 2003 2003 December 2
<d1>/<d2>/<d4> 84 7/30/2015 2015 July 30
<d2>/<d2>/<d4> 80 04/04/2002 2002 April 4
<d4>-<d1>-<d1> 54 2020-3-2 2020 March 2
{{<u><d1><u>|<d2> <u><l> <d4>}} 39 {{J2G|30 August 1585}} ???
<d4>/<d2>/<d2> 32 2006/01/17 2006 January 17
<d2> <u><l>, <d4> 30 11 Sep, 2004 2004 September 11
<d1>/<d1>/<d4> 28 7/7/2015 2015 July 7
<d4> <u><l> 25 1993 April 1993 April
<d1>/<d2>/<d2> 19 3/24/15 2015 March 24
<d4>, <d2> <u><l> 14 2017, 14 November 2017 November 14
<d2>/<d2>/<d2> 13 07/23/17 2017 July 23
<d1> <u><l>, <d4> 12 7 January, 1837 1837 January 7
<d2>/<d1>/<d4> 12 10/4/2014 2014 October 4
<d4>-<d2>-<d1> 12 1707-04-7 1707 April 7
<d2> <u><l> <d2> 11 12 May 92 1992 May 12
<u><l> 10 February ???
<d2>.<d2>.<d4> 9 21.10.2014 2014 October 21
<d4>-<d2>-<d2><u><d2>:<d2>:<d2> 8 2002-12-18T04:19:52 2002 December 18
<u> <d2>, <d4> 8 APR 17, 2015 2015 April 17
<u><l> <d2> 8 September 30 ???
<u><l> <d2><l>, <d4> 8 February 11th, 1839 1839 February 11
<d1>/<d1>/<d2> 7 4/1/15 2015 April 1
<d2>-<d1>-<d4> 7 14-4-2017 2017 April 14
<d4>, <u><l> <d2> 7 2017, February 16 2017 February 16
<d2>-<d2>-<d2> 6 08-12-31 2008 December 31
<d4>/<d1>/<d2> 6 1995/8/21 1995 August 21
<u><l>, <d4> 6 November, 2018 2018 November
<d1>-<d1>-<d4> 5 1-5-1840 1840 May 1
<d2>-<u><l>-<d2> 5 15-Jul-83 1983 July 15
<d4>, <d1> <u><l> 5 2017, 2 March 2017 March 2
<d4>-<d2>-<d2><u><d2>:<d2> 5 1992-12-08T22:34 1992 December 8
<u><l> <d1>,<d4> 5 August 8,1864 1864 August 8
<u><l> <d1><l>, <d4> 5 March 3rd, 2020 2020 March 3
<u><l> <d2>,<d4> 5 February 24,2016 2016 ???
{{<u><d1><u>|<d1> <u><l> <d4>}} 5 {{J2G|2 January 1579}} ???
<d2> <l> <d4> 4 14 august 2017 2017 August 14
<d1>-<d2>-<d4> 3 9-11-2017 2017 November 9
<d1>-<u><l>-<d2> 3 8-Mar-87 1987 March 8
<d2>.<d1>.<d4> 3 23.1.2020 2020 January 23
<d2>/<d1>/<d2> 3 01/6/17 2017 January 6
<d4>, <u><l> <d1> 3 2018, January 5 2018 January 5
<u> <d1>, <d4> 3 APR 5, 2019 2019 April 5
<u><l> <d2>. <d4> 3 May 27. 2010 2010 May 27
<d1> <l> <d4> 2 7 march 2018 2018 March 7
<d1> <u><l> <d2> 2 7 Jun 90 1990 June 7
<d1>. <u><l> <d4> 2 8. April 2020 2020 April 8
<d2> <u><l> <d4> <d4> 2 15 Jul 2010 2010 ???
<d2> <u><l><d4> 2 20 December1806 ???
<d2>. <u><l> <d4> 2 27. November 1844 1844 November 27
<d2>.<d2>.<d2> 2 17.03.19 ???
<d2><l> <u><l> <d4> 2 14th October 2018 2018 October 14
<d4>-<u><l>-<d2> 2 2005-May-31 2005 May 31
<l>.<l>. 2 n.d. ???
<u><l> <d1> 2 October 2 ???
<u><l> <d2>, <d4> <d4> 2 September 29, 1905 1905 ???
<u><l> <d2><l> <d4> 2 February 15th 1999 1999 February 15
<u><l>, <d2> <u><l> <d4> <d2>:<d2>:<d2> +<d4> 2 Mon, 23 Feb 2004 11:26:07 +0100 2004 February 23
<d1> <u><l> <d1> <d4> 1 9 September 9 2005 ???
<d1> <u><l> <d1>, <d4> 1 1 March 1, 1988 ???
<d1> <u><l><d4> 1 1 September1870 ???
<d1>. <l> <d4> 1 3. october 2015 2015 October 3
<d1>/<d2>/<d2> <d4> 1 4/11/03 2003 ???
<d2> <l>. <d4> 1 17 jan. 2014 2014 January 17
<d2> <u>, <d4> 1 05 SEPTEMBER, 2018 2018 September 5
<d2> <u><l> <d2> <d4> 1 27 January 27 2010 ???
<d2> <u><l> <d4>. 1 25 February 1996. ???
<d2>-<d1>-<d2> 1 05-2-27 ???
<d2>. <l> <d4> 1 02. october 2018 2018 October 2
<d2>.<d1>.<d4>-<d2>-<d2> 1 30.6.2011-06-30 ???
<d2>/<d2>, <d4> 1 11/19, 2015 November 19
<d4>, <u><l> <d1><l> 1 2011, October 7th 2011 October 7
<d4>-<d1> 1 1974-5 1974 May
<d4>-<d2>-<d2><u><d2>:<d2>:<d2>+<d4> 1 2008-09-25T20:53:38+0200 2008 September 25
<d4>...<d4> 1 2005...2011 ???
<l> <d1>, <d4> 1 october 7, 2013 2013 October 7
<l> <d2>, <d4> 1 january 26, 2018 2018 January 26
<u> <d2> <u> <d4> 1 SATURDAY 02 MARCH 2019 2019 March 2
<u><l> <d1>, <d4>. 1 March 4, 2016. 2016 March 4
<u><l> <d1>. <d4> 1 February 7. 2008 2008 February 7
<u><l> <d1><l> <d4> 1 June 4th 2009 2009 June 4
<u><l> <d2>, <d4>-<d1> 1 March 23, 1658-9 1658-9 March 23
<u><l> <d2>, <d4>. 1 Dec 16, 2015. 2015 December 16
<u><l> <d4> <d4> 1 February 2010 2010 ???
<u><l> <d4>, <d4> 1 September 2003, 2003 ???
<u><l>, <d2> <u><l> <d4> <d2>:<d2>:<d2> <u> 1 Sat, 22 Sep 2001 22:12:03 GMT 2001 September 22
<u><l>, <d2> <u><l> <d4> <d4> 1 Wed, 28 Feb 2001 2001 ???
<u><l>, <d2>-<u><l>-<d2> 1 Wed, 14-Nov-84 1984 November 14
<u><l>, <u><l> <d1><l>, <d4> 1 Saturday, December 7th, 2019 2019 December 7
<u><l>. <d2> <d4> 1 Dec. 16 2014 2014 December 16
<u><l>.<d2>, <d4> 1 Nov.12, 1996 1996 November 12
<u><l><d2>, <d4> 1 January20, 2010 ???
<u><l><u> <d2>, <d4> 1 SeptembeR 24, 2011 2011 September 24]]
return export