Documentation for this module may be created at Module:Author/testcases/doc
-- Unit tests for [[Module:Author]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local Author = require('Module:Author')
function p:test_dates_supplied()
local out
-- No dates.
out = '[[Category:Authors with missing birth dates]][[Category:Authors with missing death dates]]'
self:preprocess_equals('{{#invoke:Author|dates}}', out, {nowiki=1})
-- Manual dates.
out = '<br />(Manual dates)[[Category:Authors with missing birth dates]][[Category:Authors with missing death dates]][[Category:Authors with override dates]]'
self:preprocess_equals('{{#invoke:Author|dates|dates=Manual dates}}', out, {nowiki=1})
-- Manual dates, but also birth and death dates (for categories).
out = '<br />(Manual dates)[[Category:1904 births]][[Category:1960s deaths]][[Category:Authors with non-numeric death dates]]'
.. '[[Category:Authors with override birth dates]][[Category:Authors with override dates]][[Category:Authors with override death dates]][[Category:Modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|dates=Manual dates|birthyear=1904|deathyear=1960s}}', out, {nowiki=1})
-- Exact years (both)
out = '<br />(1810–1890)[[Category:1810 births]][[Category:1890 deaths]][[Category:Authors with override birth dates]][[Category:Authors with override death dates]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|dates=|birthyear=1810|deathyear=1890}}', out, {nowiki=1})
-- Exact birth year and approximate death year
out = '<br />(1810 – c. 1890)[[Category:1810 births]][[Category:1890 deaths]][[Category:Authors with approximate death dates]][[Category:Authors with override birth dates]]'
.. '[[Category:Authors with override death dates]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|birthyear=1810|deathyear=c./1890}}', out, {nowiki=1})
-- Approximate birth year and unknown death year
out = '<br />(c. 1810 – ?)[[Category:1810 births]][[Category:? deaths]][[Category:Authors with approximate birth dates]][[Category:Authors with non-numeric death dates]][[Category:Authors with override birth dates]]'
.. '[[Category:Authors with override death dates]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|birthyear=ca/1810|deathyear=?}}', out, {nowiki=1})
-- Multiple birth dates.
out = '<br />(1932/1933–)[[Category:1932 births]][[Category:1933 births]]'
.. '[[Category:Authors with approximate birth dates]][[Category:Authors with missing death dates]][[Category:Authors with override birth dates]][[Category:Modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|birthyear=1932/1933|deathyear=|wikidata_id=}}', out, {nowiki=1})
end
function p:test_dates_wikidata()
local out
-- Both dates exact to the day.
local janeAusten = 'Q36322'
out = '<br />(1775–1817)[[Category:1775 births]][[Category:1817 deaths]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. janeAusten .. '|birthyear=|deathyear=|dates=}}', out, {nowiki=1})
-- Dates not matching.
out = '<br />(1900–1817)[[Category:1775 births]][[Category:1817 deaths]][[Category:1900 births]]'
.. '[[Category:Authors with birth dates differing from Wikidata]][[Category:Authors with override birth dates]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. janeAusten .. '|birthyear=1900}}', out, {nowiki=1})
out = '<br />(1775–1817)[[Category:1775 births]][[Category:1817 deaths]][[Category:Authors with title-date mismatches]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. janeAusten .. '|pagetitle=Jane Austen (1770-1817)}}', out, {nowiki=1})
out = '<br />(1775–1817)[[Category:1775 births]][[Category:1817 deaths]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. janeAusten .. '|pagetitle=Jane Austen (mechanic)}}', out, {nowiki=1})
-- Exact birth, century-only death.
-- FIXME: Wikidata item is no longer representative
-- local helenaFenwickDale = 'Q20204408'
-- out = '<br />(1854 – 20th century)[[Category:1854 births]][[Category:20th century deaths]][[Category:Authors with approximate death dates]][[Category:Early modern authors]][[Category:Modern authors]]'
-- self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. helenaFenwickDale .. '}}', out, {nowiki=1})
-- Unknown birth, century-only death.
-- FIXME: Wikidata item is no longer representative
-- local johnBarr = 'Q16004141'
-- out = '<br />(? – 20th century)[[Category:20th century deaths]][[Category:Authors with approximate death dates]][[Category:Authors with unknown birth dates]][[Category:Modern authors]]'
-- self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. johnBarr .. '}}', out, {nowiki=1})
-- Multiple dates of birth. [[Author:David]]
out = '<br />(1039 BCE – 969 BCE)[[Category:1039 BCE births]][[Category:969 BCE deaths]][[Category:Ancient authors]]'
self:preprocess_equals( '{{#invoke:Author|dates|wikidata_id=Q41370}}', out, {nowiki=1} )
-- Multiple death dates in the same year
local johnKnox = 'Q189937'
out = '<br />(c. 1514 – 1572)[[Category:1514 births]][[Category:1572 deaths]][[Category:Authors with approximate birth dates]][[Category:Renaissance authors]]'
self:preprocess_equals( '{{#invoke:Author|dates|wikidata_id='.. johnKnox .. '}}', out, {nowiki=1} )
-- Living person.
out = '<br />(1942–)[[Category:1942 births]][[Category:Authors with missing death dates]][[Category:Living authors]][[Category:Modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q6279}}', out, {nowiki=1})
-- No dates provided. Manu (Q178744, first human being in Hindu tradition). Only humans are called 'living' by default.
out = '[[Category:Authors with missing birth dates]][[Category:Authors with missing death dates]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q178744}}', out, {nowiki=1})
-- 4th century dates, where birth and death are the same.
out = '<br />(4th century)[[Category:4th century births]][[Category:4th century deaths]][[Category:Ancient authors]][[Category:Authors with approximate birth dates]][[Category:Authors with approximate death dates]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q782401}}', out, {nowiki=1})
-- Floruit (with birth and death dates = 'unknown').
out = '<br />(fl. 1735)[[Category:Authors with floruit dates]][[Category:Authors with unknown birth dates]][[Category:Authors with unknown death dates]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q28585286}}', out, {nowiki=1})
-- Floruit with no death date.
-- FIXME: Wikidata item is no longer representative
-- out = '<br />(fl. c. 509 BCE)[[Category:Ancient authors]][[Category:Authors with approximate floruit dates]][[Category:Authors with floruit dates]][[Category:Authors with missing birth dates]][[Category:Authors with missing death dates]]'
-- self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q241132}}', out, {nowiki=1})
-- First century BCE, where birth and death are the same.
out = '<br />(1st century BCE)[[Category:1st century BCE births]][[Category:1st century BCE deaths]][[Category:Ancient authors]][[Category:Authors with approximate birth dates]][[Category:Authors with approximate death dates]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q670317}}', out, {nowiki=1})
out = '<br />(fl. 1900s)[[Category:Authors with approximate floruit dates]][[Category:Authors with floruit dates]][[Category:Authors with unknown birth dates]][[Category:Authors with unknown death dates]][[Category:Early modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q28811762}}', out, {nowiki=1})
-- Multiple floruit dates.
-- FIXME: Wikidata item is no longer representative
-- out = '<br />(fl. 1875–1915)[[Category:Authors with approximate floruit dates]][[Category:Authors with floruit dates]][[Category:Authors with unknown birth dates]][[Category:Authors with unknown death dates]][[Category:Modern authors]]'
-- self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q55222075}}', out, {nowiki=1})
-- Floruit date more than 110 years ago and no death date.
out = '<br />(fl. 1521)[[Category:Authors with floruit dates]][[Category:Authors with missing birth dates]][[Category:Authors with missing death dates]][[Category:Renaissance authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q56438002}}', out, {nowiki=1})
out = '<br />(1965–)[[Category:1965 births]][[Category:Authors with missing death dates]][[Category:Living authors]][[Category:Modern authors]]'
self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q34660}}', out, {nowiki=1})
end
function p:test_date()
-- Supplied years.
self:preprocess_equals('{{#invoke:Author|date|year=1820}}', '1820')
self:preprocess_equals('{{#invoke:Author|date|year=c./1820}}', 'c. 1820')
self:preprocess_equals('{{#invoke:Author|date|year=1820s}}', '1820s')
self:preprocess_equals('{{#invoke:Author|date|year=1820?}}', '1820?')
self:preprocess_equals('{{#invoke:Author|date|year=1820/?}}', '1820?')
self:preprocess_equals('{{#invoke:Author|date|year=1932/1933}}', '1932/1933')
-- Approximate birth date.
self:preprocess_equals('{{#invoke:Author|date|type=birth|wikidata_id=Q3276100}}', '19th century')
self:preprocess_equals('{{#invoke:Author|date|type=death|wikidata_id=Q563504}}', '17th century BCE')
-- Multiple dates of birth, [[Author:Alain de Lille]].
self:preprocess_equals('{{#invoke:Author|date|wikidata_id=Q4313|type=birth}}', '1110s/1114/1115')
-- Exact death date, [[Author:Jane Austen]].
self:preprocess_equals('{{#invoke:Author|date|wikidata_id=Q36322|type=death}}', '1817')
-- Empty death date for living (JK Rowling)
self:preprocess_equals('{{#invoke:Author|date|wikidata_id=Q34660|type=death}}', '' )
-- Empty wikidata_id parameter.
self:preprocess_equals('{{#invoke:Author|date|type=birth|wikidata_id=}}', '')
end
--[=[
Simple test for the wikicode string
]=]
function p:test_categories_wikicode()
self:preprocess_equals('{{#invoke:Author|categories|wikidata_id=Q1103678}}',
'[[Category:United States authors]]\n[[Category:Anthropologists as authors]]\n[[Category:Sociologists as authors]]\n',
{nowiki=1})
self:preprocess_equals('{{#invoke:Author|categories|wikidata_id=Q1103678}}',
'[[Category:United States authors]]\n[[Category:Anthropologists as authors]]\n[[Category:Sociologists as authors]]\n',
{nowiki=1})
self:preprocess_equals('{{#invoke:Author|categories|wikidata_id=Q474235}}',
'[[Category:United States authors]]\n[[Category:Philosophers as authors]]\n[[Category:Educators as authors]]\n[[Category:Transcendentalists]]\n',
{nowiki=1})
end
function p:test_last_initial()
local out
--[=[ No Wikidata, has no initials, so added to category.
self:preprocess_equals(
'{{#invoke:Author|lastInitial|wikidata_id=Q34660|last_initial=}}',
'[[Category:Authors without initials]]',
{nowiki=1}
) ]=]
-- Has Wikidata with family name (J.K. Rowling).
self:preprocess_equals(
'{{#invoke:Author|lastInitial|wikidata_id=Q34660|last_initial=}}',
'[[Wikisource:Authors-Ro|Author Index: Ro]][[Category:Authors-Ro]]',
{nowiki=1}
)
-- Has Wikidata with family name (J.K. Rowling), but has local override.
self:preprocess_equals(
'{{#invoke:Author|lastInitial|wikidata_id=Q34660|last_initial=Qq}}',
'[[Wikisource:Authors-Qq|Author Index: Qq]][[Category:Authors-Qq]][[Category:Author pages with missing initials category]]',
{nowiki=1}
)
-- {{disambiguation}} template override
self:preprocess_equals(
'{{#invoke:Author|lastInitial|wikidata_id=Q34660|last_initial=!NO_INITIALS}}',
'',
{nowiki=1}
)
end
return p