Module:Infobox/dates/testcases
Appearance
< Module:Infobox | dates
![]() | This is the test cases page for the module Module:Infobox/dates. Results of the test cases. |
-- Unit tests for [[Module:Infobox/dates/testcases]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local function expandTemplate(template, value)
local frame = mw.getCurrentFrame()
return frame:expandTemplate{title = template, args = value}
end
local start_date_default = {"2015", "4", "23"}
local end_date_default = {"2016", "4", "23"}
local start_date_default_plain = "April 23, 2015"
local end_date_default_plain = "April 23, 2016"
function p:test_01_valid()
self:preprocess_equals_sandbox_many('{{#invoke:Infobox/dates', 'dates', {
-- With templates
{'1=' .. expandTemplate("start date", start_date_default), ''},
{'1=' .. expandTemplate("end date", end_date_default), ''},
{'1=' .. expandTemplate("start date", start_date_default) .. '|2=' .. expandTemplate("end date", end_date_default), ''}, -- different years
{'1=' .. expandTemplate("start date", start_date_default) .. '|2=' .. expandTemplate("end date", {"2015", "5", "23"}), ''}, -- same years, different months
{'1=' .. expandTemplate("start date", start_date_default) .. '|2=' .. expandTemplate("end date", {"2015", "4", "24"}), ''}, -- same years and months, different days
{'1=' .. expandTemplate("start date", start_date_default) .. '|2=' .. expandTemplate("end date", start_date_default), ''}, -- same date
{'1=' .. expandTemplate("start date", start_date_default) .. '|2=present', ''}, -- to present
-- Without templates
{start_date_default_plain, ''},
{end_date_default_plain, ''},
{start_date_default_plain .. '|' .. end_date_default_plain, ''}, -- different years
{start_date_default_plain .. '|May 23, 2015', ''}, -- same years, different months
{start_date_default_plain .. '|May 24, 2015', ''}, -- same years and months, different days
{start_date_default_plain .. '|' .. start_date_default_plain, ''}, -- same date
{start_date_default_plain .. '|present', ''}, -- to present
-- Partial dates with templates
{expandTemplate("start date", {"2015"}) .. '|' .. expandTemplate("end date", {"2016"}), ''}, -- just years
{expandTemplate("start date", {"2015"}) .. '|' .. expandTemplate("end date", {"2015"}), ''}, -- just years, same year
{expandTemplate("start date", {"2015", "4"}) .. '|' .. expandTemplate("end date", {"2016", "5"}), ''}, -- years and months, different months
{expandTemplate("start date", {"2015", "4"}) .. '|' .. expandTemplate("end date", {"2016", "4"}), ''}, -- years and months, same months
-- Partial dates without templates
{'2015|2016', ''}, -- just years
{'2015|2015', ''}, -- just years, same year
{'April 2015|May 2016', ''}, -- years and months, different months
{'April 2015|April 2016', ''}, -- years and months, same months
})
end
-- do the same with df=yes
function p:test_02_valid_df()
self:preprocess_equals_sandbox_many('{{#invoke:Infobox/dates', 'dates|df=y', {
-- With templates
{expandTemplate("start date", start_date_default), ''},
{expandTemplate("end date", end_date_default), ''},
{expandTemplate("start date", start_date_default) .. '|' .. expandTemplate("end date", end_date_default), ''}, -- different years
{expandTemplate("start date", start_date_default) .. '|' .. expandTemplate("end date", {"2015", "5", "23"}), ''}, -- same years, different months
{expandTemplate("start date", start_date_default) .. '|' .. expandTemplate("end date", {"2015", "4", "24"}), ''}, -- same years and months, different days
{expandTemplate("start date", start_date_default) .. '|' .. expandTemplate("end date", start_date_default), ''}, -- same date
{expandTemplate("start date", start_date_default) .. '|present', ''}, -- to present
-- Without templates
{start_date_default_plain, ''},
{end_date_default_plain, ''},
{start_date_default_plain .. '|' .. end_date_default_plain, ''}, -- different years
{start_date_default_plain .. '|May 23, 2015', ''}, -- same years, different months
{start_date_default_plain .. '|May 24, 2015', ''}, -- same years and months, different days
{start_date_default_plain .. '|' .. start_date_default_plain, ''}, -- same date
{start_date_default_plain .. '|present', ''}, -- to present
-- Partial dates with templates
{expandTemplate("start date", {"2015"}) .. '|' .. expandTemplate("end date", {"2016"}), ''}, -- just years
{expandTemplate("start date", {"2015"}) .. '|' .. expandTemplate("end date", {"2015"}), ''}, -- just years, same year
{expandTemplate("start date", {"2015", "4"}) .. '|' .. expandTemplate("end date", {"2016", "5"}), ''}, -- years and months, different months
{expandTemplate("start date", {"2015", "4"}) .. '|' .. expandTemplate("end date", {"2016", "4"}), ''}, -- years and months, same months
-- Partial dates without templates
{'2015|2016', ''}, -- just years
{'2015|2015', ''}, -- just years, same year
{'April 2015|May 2016', ''}, -- years and months, different months
{'April 2015|April 2016', ''}, -- years and months, same months
})
end
function p:test_03_invalid_range()
self:preprocess_equals_sandbox_many('{{#invoke:Infobox/dates', 'dates', {
-- end date starts before start date
{expandTemplate("start date", end_date_default) .. '|' .. expandTemplate("end date", start_date_default), ''},
{end_date_default_plain .. '|' .. start_date_default_plain, ''},
})
end
return p