Module:Complex date/testcases
Jump to navigation
Jump to search
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
Lua
Documentation for this module may be created at Module:Complex date/testcases/doc
Code
local p = require('Module:UnitTests')
-- To disable one of the test functions below, to run it separately, you may just need
-- to change the prefix "test" into "_test" in the function name.
-- The names of tests are sorted alphabetically, and used to indicate their order
-- of execution; it is also used to generate a caption for its results table:
-- * After the required prefix "test" or "test_", you can put a number terminated by
-- an underscore (numbers should then be sorted in this file so that tests will run in
-- the same order, even if each test should be independant).
-- * The rest of the test name is an arbitrary identifier to name the test.
-- * Double underscores in that name are changed into a SPACE in the caption.
------------------------------------------------------------------------------------------------------
local langs = { -- comprehensive list
-- 'ab',
-- 'als',
-- 'am',
'ar',
-- 'as',
-- 'ast',
'az',
'be',
'bg',
'bn',
-- 'br',
-- 'bs',
'ca',
-- 'ce',
-- 'co',
'cs',
'da',
'de',
-- 'dsb',
-- 'el',
'en',
-- 'eo',
'es',
-- 'et',
-- 'eu',
-- 'ext',
'fa',
'fi',
'fr',
-- 'fy',
-- 'ga',
'gl',
-- 'gsw',
-- 'gu',
-- 'ha',
'he',
'hi',
'hr',
-- 'hsb',
'hu',
-- 'hy',
'id',
-- 'is',
'it',
'ja',
'jv',
-- 'ka',
-- 'kk',
-- 'km',
-- 'kn',
'ko',
-- 'ku',
-- 'la',
-- 'lb',
-- 'li',
-- 'lo',
'lt',
'lv',
-- 'mg',
-- 'mi',
-- 'mk',
'ml',
-- 'mn',
-- 'ms',
-- 'mt',
-- 'nds',
-- 'ne',
'nl',
-- 'nn',
'nb',
'or',
-- 'pa',
'pl',
-- 'ps',
'pt',
-- 'qu',
'ro',
'ru',
'sa',
-- 'sd',
'sk',
-- 'sl',
-- 'sq',
'sr',
-- 'su',
'sv',
'ta',
-- 'te',
-- 'tg',
'th',
-- 'tk',
-- 'tl',
'tr',
'uk',
-- 'ur',
-- 'uz',
-- 'vec',
'vi',
-- 'wa',
-- 'wo',
-- 'wuu',
-- 'xh',
-- 'yi',
-- 'yue',
-- 'zea',
'zh-hans',
-- 'zh-hant',
-- 'zu',
}
------------------------------------------------------------------------------------------------------
function p:test1a_Years__with__era()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'AD|456'},
{'BC|123'},
}, {nowiki=1, varying=1})
end
end
function p:test1b_Half__open__intervals()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'before|1999-05'},
{'after|2000'},
}, {nowiki=1, varying=1})
end
end
function p:test1c_Two_dates()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'or|1999|2000'},
{'&|1999|2000'},
--{'conj=and|adj1=late|date1=1999|adj2=early|date2=2000','year turn|2000'},
}, {nowiki=1, varying=1})
end
end
------------------------------------------------------------------------------------------------------
local langs = { -- partial list
'ar',
'cs',
'de',
'en',
'es',
'fa',
'fi',
'fr',
'it',
'ja',
'nl',
'nb',
'pl',
--'qu',
'ru',
'sl',
'sv',
'uk',
'vi',
'zh',
}
------------------------------------------------------------------------------------------------------
function p:_test2a_Unknown()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang='.. lang ..'}}', {
{'year unknown'},
{'unknown'},
}, {nowiki=1, varying=1})
end
end
function p:test2b_Common__periods()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'millennium|2'},
{'century|19'},
{'decade|1990'},
{'circa|1999'},
}, {nowiki=1, varying=1})
end
end
function p:test2c_Years__with__era()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'AD|1999'},
{'BC|1999'},
{'BP|900'},
{'AH|278'},
}, {nowiki=1, varying=1})
end
end
function p:_test2d_Intervals__of__years()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'circa|1999|2001'},
{'between|1999|2000'},
{'-|1999|2000'},
{'julian|1999|2000'},
{'islamic|1999|2000'},
--{'conj=between|adj1=circa|date1=1999|adj2=circa|date2=2000','circa|1999|2000'},
}, {nowiki=1, varying=1})
end
end
function p:_test2e_Parts__of__year()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'spring|1999'},
{'summer|1999'},
{'fall|1999'},
{'winter|1999'},
{'beginning|1999'},
{'middle|1999'},
{'end|1999'},
{'1half|1999'},
{'2half|1999'},
{'1quarter|1999'},
{'2quarter|1999'},
{'3quarter|1999'},
{'4quarter|1999'},
}, {nowiki=1, varying=1})
end
end
function p:_test2f_Parts__of__month()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'beginning|1999-01'},
{'middle|1999-07'},
{'end|1999-12'},
{'1half|1999-01'},
{'2half|1999-06'},
{'1quarter|1999-01'},
{'2quarter|1999-04'},
{'3quarter|1999-07'},
{'4quarter|1999-10'},
}, {nowiki=1, varying=1})
end
end
function p:_test2g_Turns__of()
for _, lang in ipairs(langs) do
self:preprocess_equals_preprocess_many(
'{{#invoke:Complex date|complex_date|', '|lang=' .. lang .. '}}',
'{{Other date/old|', '|lang=' .. lang .. '}}', {
{'turn of the century|19'},
{'turn of the century|3|era=BC'},
{'turn of the decade|1990'},
{'turn of the decade|190|era=BC'},
{'turn of the year|1999'},
{'turn of the year|98|era=BC'},
{'by|1999'},
{'from|2000-06-06'},
}, {nowiki=1, varying=1})
end
end
------------------------------------------------------------------------------------------------------
function p:_test_en__only__with__a__single__date()
self:preprocess_equals_many(
'{{#invoke:complex_date|complex_date|lang=en|', '}}', {
{'date1=1234-05-06 ', '<span style="white-space:nowrap"><time class="dtstart" datetime="1234-05-06">6 May 1234</time></span>'},
{'date1=1234-05 ', '<span style="white-space:nowrap"><time class="dtstart" datetime="1234-05">May 1234</time></span>'},
{'date1=1234 ', '<span style="white-space:nowrap"><time class="dtstart" datetime="1234">1234</time></span>'},
{'date1=1230 |precision1=decade ', '1230s<div style="display: none;">date QS:P,+1230-00-00T00:00:00Z/8</div>'},
{'date1=1200 |precision1=century ', '13<sup>th</sup> century<div style="display: none;">date QS:P,+1250-00-00T00:00:00Z/7</div>'},
{'date1=21 |precision1=century ', '21<sup>st</sup> century<div style="display: none;">date QS:P,+2050-00-00T00:00:00Z/7</div>'},
{'date1=2000 |precision1=millennium ', '3<sup>rd</sup> millennium<div style="display: none;">date QS:P,+2500-00-00T00:00:00Z/6</div>'},
{'date1=2 |precision1=millennium ', '2<sup>nd</sup> millennium<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6</div>'},
-- non-breaking space (U+00A0) between year and "BC" / "BCE" / "BP"
{'date1=1234-05-06 |era1=BC ', '6 May 1234 [[w:en:Ante Christum Natum|BC]]<div style="display: none;">date QS:P,-1234-05-06T00:00:00Z/11</div>'},
{'date1=1234-05-06 |era1=BCE ', '6 May 1234 [[w:en:Ante Christum Natum|BC]]<div style="display: none;">date QS:P,-1234-05-06T00:00:00Z/11</div>'},
{'date1=1234-05-06 |era1=BP ', '6 May 1234 [[w:en:Before Present|BP]]<div style="display: none;">date QS:P,-1234-05-06T00:00:00Z/11</div>'},
-- "CE" and "AD" notation is different; for why "AD" comes before the year, see preface of this article: https://en.wikipedia.org/wiki/Anno_Domini
-- non-breaking space (U+00A0) between "AD" and year, and between year and "CE"
{'date1=1234-05-06 |era1=AD ', '6 May [[w:en:Anno Domini|AD]] 1234<div style="display: none;">date QS:P,+1234-05-06T00:00:00Z/11</div>'},
{'date1=1234-05-06 |era1=CE ', '6 May 1234 [[w:en:Common Era|CE]]<div style="display: none;">date QS:P,+1234-05-06T00:00:00Z/11</div>'},
{'date1=1234 |era1=AH ', '1234 [[w:en:Hijri year|AH]]'},
{'date1=1230 |precision1=decade |era1=AH ', '1230s [[w:en:Hijri year|AH]]'},
{'date1=10 |precision1=century |era1=AH ', '10<sup>th</sup> century [[w:en:Hijri year|AH]]'},
{'date1=1 |precision1=millennium |era1=AH ', '1<sup>st</sup> millennium [[w:en:Hijri year|AH]]'},
}, {nowiki=1, varying=1}
)
end
function p:_test_en__only__with__an__interval__or__two__dates()
self:preprocess_equals_many(
'{{#invoke:complex_date|complex_date|lang=en|', '}}', {
{'date1=1111-11-11 |conj=- |date2=1234-05-06 ', 'from 11 November 1111 until 6 May 1234<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P580,+1111-11-11T00:00:00Z/11,P582,+1234-05-06T00:00:00Z/11</div>'},
{'date1=1111-11-11 |conj=between |date2=1234-05-06 ', 'between 11 November 1111 and 6 May 1234<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P1319,+1111-11-11T00:00:00Z/11,P1326,+1234-05-06T00:00:00Z/11</div>'},
{'date1=1111-11-11 |conj=or |date2=1234-05-06 ', '11 November 1111 or 6 May 1234'},
{'date1=1111-11-11 |conj=and |date2=1234-05-06 ', '11 November 1111 and 6 May 1234'},
}, {nowiki=1, varying=1}
)
end
------------------------------------------------------------------------------------------------------
function p:_test_ru__only__with__a__single__date()
self:preprocess_equals_many(
'{{#invoke:complex_date|complex_date|lang=ru|', '}}', {
{'date1=1234-05-06 ', '<span style="white-space:nowrap"><time class="dtstart" datetime="1234-05-06">6 мая 1234</time></span>'},
{'date1=1234-05 ', '<span style="white-space:nowrap"><time class="dtstart" datetime="1234-05">май 1234</time></span>'},
{'date1=1234 ', '<span style="white-space:nowrap"><time class="dtstart" datetime="1234">1234</time></span>'},
-- non-breaking hyphen (U+2011) between the year and the letter "е"
{'date1=1230 |precision1=decade ', '1230‑е годы<div style="display: none;">date QS:P,+1234-00-00T00:00:00Z/8</div>'},
-- non-breaking space (U+00A0)
{'date1=1200 |precision1=century ', 'XIII век<div style="display: none;">date QS:P,+1250-00-00T00:00:00Z/7</div>'},
{'date1=21 |precision1=century ', 'XXI век<div style="display: none;">date QS:P,+1950-00-00T00:00:00Z/7</div>'},
-- non-breaking space (U+00A0)
{'date1=2000 |precision1=millennium ', 'III тысячелетие<div style="display: none;">date QS:P,+2500-00-00T00:00:00Z/6</div>'},
{'date1=2 |precision1=millennium ', 'II тысячелетие<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6</div>'},
-- non-breaking spaces (U+00A0) in "XXXX г.", "до н. в.", "до н. э.", "н. э."
{'date1=1234-05-06 |era1=BC ', '6 мая 1234 г. до н. э.<div style="display: none;">date QS:P,-1234-05-06T00:00:00Z/11</div>'},
{'date1=1234-05-06 |era1=BCE ', '6 мая 1234 г. до н. э.<div style="display: none;">date QS:P,-1234-05-06T00:00:00Z/11</div>'},
{'date1=1234-05-06 |era1=BP ', '6 мая 1234 г. [[w:ru:До настоящего времени|до н. в.]]<div style="display: none;">date QS:P,-1234-05-06T00:00:00Z/11</div>'},
{'date1=1234-05-06 |era1=CE ', '6 мая 1234 г. н. э.<div style="display: none;">date QS:P,+1234-05-06T00:00:00Z/11</div>'},
{'date1=1234-05-06 |era1=AD ', '6 мая 1234 г. н. э.<div style="display: none;">date QS:P,+1234-05-06T00:00:00Z/11</div>'},
-- non-breaking spaces (U+00A0) in "* век" and "* тысячелетие"
{'date1=1234 |era1=AH', '1234 год [[w:ru:Исламский календарь|хиджры]]'},
{'date1=1230 |precision1=decade |era1=AH ', '1230-е годы [[w:ru:Исламский календарь|хиджры]]'},
{'date1=10 |precision1=century |era1=AH ', 'X век [[w:ru:Исламский календарь|хиджры]]'},
{'date1=1 |precision1=millennium |era1=AH ', 'I тысячелетие [[w:ru:Исламский календарь|хиджры]]'},
}, {htmlize=1, varying=1}
)
end
function p:_test_ru__only__with__an__interval__or__two__dates()
self:preprocess_equals_many(
'{{#invoke:complex_date|complex_date|lang=ru|', '}}', {
{'date1=1111-11-11 |conj=- |date2=1234-05-06 ', 'с 11 ноября 1111 по 6 мая 1234<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P580,+1111-11-11T00:00:00Z/11,P582,+1234-05-06T00:00:00Z/11</div>'},
{'date1=1111-11-11 |conj=between |date2=1234-05-06 ', 'между 11 ноября 1111 и 6 мая 1234<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P1319,+1111-11-11T00:00:00Z/11,P1326,+1234-05-06T00:00:00Z/11</div>'},
{'date1=1111-11-11 |conj=or |date2=1234-05-06 ', '11 ноября 1111 или 6 мая 1234'},
{'date1=1111-11-11 |conj=and |date2=1234-05-06 ', '11 ноября 1111 и 6 мая 1234'},
{'date1=1111-10 |conj=- |date2=1111-11 ', 'с октября по ноябрь 1111<div style="display: none;">date QS:P,+1111-00-00T00:00:00Z/9,P580,+1111-10-00T00:00:00Z/10,P582,+1111-11-00T00:00:00Z/10</div>'},
{'date1=1111-12 |conj=- |date2=1112-1 ', 'с декабря 1111 по январь 1112'},
{'date1=1100 |conj=- |date2=1111 ', 'с 1100 по 1111<div style="display: none;">date QS:P,+1150-00-00T00:00:00Z/7,P580,+1100-00-00T00:00:00Z/9,P582,+1111-00-00T00:00:00Z/9</div> '},
-- non-breaking spaces (U+00A0) in "XXXX г.", * век*", "* тысячелети*";
-- non-breaking hyphen (U+2011) between year and the endings "x", "е", "ми"
{'date1=1119 |precision1=year |conj=- |date2=1120 |precision2=decade ', 'с 1119 г. по 1120‑е годы<div style="display: none;">date QS:P,+1150-00-00T00:00:00Z/7,P580,+1119-00-00T00:00:00Z/9,P582,+1120-00-00T00:00:00Z/8</div>'},
{'date1=1110 |precision1=decade |conj=- |date2=1123 |precision2=year ', 'с 1110‑х годов по 1123 г.<div style="display: none;">date QS:P,+1150-00-00T00:00:00Z/7,P580,+1110-00-00T00:00:00Z/8,P582,+1123-00-00T00:00:00Z/9</div> '},
{'date1=1100 |precision1=decade |conj=- |date2=1110 |precision2=decade ', 'с 1100‑х по 1110‑е годы<div style="display: none;">date QS:P,+1150-00-00T00:00:00Z/7,P580,+1100-00-00T00:00:00Z/8,P582,+1110-00-00T00:00:00Z/8</div>'},
{'date1=1190 |precision1=decade |conj=- |date2=1200 |precision2=century ', 'с 1190‑х годов по XIII век<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P580,+1190-00-00T00:00:00Z/8,P582,+1250-00-00T00:00:00Z/7</div>'},
{'date1=12 |precision1=century |conj=- |date2=1210 |precision2=decade ', 'с XII века по 1210‑е годы<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P580,+1150-00-00T00:00:00Z/7,P582,+1210-00-00T00:00:00Z/8</div>'},
{'date1=1100 |precision1=century |conj=- |date2=13 |precision2=century ', 'с XII по XIII век<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P580,+1150-00-00T00:00:00Z/7,P582,+1250-00-00T00:00:00Z/7</div>'},
{'date1= 990 |precision1=decade |conj=- |date2=2 |precision2=millennium ', 'с 990‑х годов по II тысячелетие'},
{'date1=0000 |precision1=millennium |conj=- |date2=1010 |precision2=decade ', 'с I тысячелетия по 1010‑е годы'},
{'date1=1 |precision1=millennium |conj=- |date2=2 |precision2=millennium ', 'с I по II тысячелетие'},
{'date1= 9 |precision1=century |conj=- |date2=2 |precision2=millennium ', 'с IX века по II тысячелетие'},
{'date1=1 |precision1=millennium |conj=- |date2=12 |precision2=century ', 'с I тысячелетия по XII век'},
{'date1=1100 |precision1=decade |conj=between |date2=1110 |precision2=decade ', 'между 1100‑ми и 1110‑ми годами<div style="display: none;">date QS:P,+1150-00-00T00:00:00Z/7,P1319,+1100-00-00T00:00:00Z/8,P1326,+1110-00-00T00:00:00Z/8</div>'},
{'date1=1100 |precision1=century |conj=between |date2=1210 |precision2=decade ', 'между XII веком и 1210‑ми годами<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P1319,+1150-00-00T00:00:00Z/7,P1326,+1210-00-00T00:00:00Z/8</div>'},
{'date1=1190 |precision1=decade |conj=between |date2=13 |precision2=century ', 'между 1190‑ми годами и XIII веком<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P1319,+1190-00-00T00:00:00Z/8,P1326,+1250-00-00T00:00:00Z/7</div>'},
{'date1=1100 |precision1=century |conj=between |date2=1200 |precision2=century ', 'между XII и XIII веком<div style="display: none;">date QS:P,+1500-00-00T00:00:00Z/6,P1319,+1150-00-00T00:00:00Z/7,P1326,+1250-00-00T00:00:00Z/7</div> '},
}, {htmlize=1, varying=1}
)
end
return p