Module:Author/sandbox/testcases

From Wikisource
Jump to navigation Jump to search
-- Unit tests for [[Module:Author]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local Author = require('Module:Author/sandbox')

function p:test_dates_supplied()
	-- No dates.
	self:preprocess_equals('{{#invoke:Author/sandbox|dates}}', '', {nowiki=1})
	
	-- Manual dates.
	self:preprocess_equals('{{#invoke:Author/sandbox|dates|dates=Manual dates}}', '<br />(Manual dates)', {nowiki=1})
	
	-- Manual dates, but also birth and death dates (for categories).
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|dates=Manual dates|birthyear=1904|deathyear=1960s}}', '<br />(Manual dates)', {nowiki=1})
    
	-- Exact years (both)
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|dates=|birthyear=1810|deathyear=1890}}', '<br />(1810–1890)', {nowiki=1})
    
	-- Exact birth year and approximate death year
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|birthyear=1810|deathyear=c./1890}}', '<br />(1810 – c. 1890)', {nowiki=1})
    
	-- Approximate birth year and unknown death year
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|birthyear=ca/1810|deathyear=?}}', '<br />(c. 1810 – ?)', {nowiki=1})
    
	-- Multiple birth dates.
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|birthyear=1932/1933|deathyear=|wikidata_id=}}', '<br />(1932/1933–)', {nowiki=1})
end

function p:test_dates_wikidata()
	-- Both dates exact to the day.
	local janeAusten = 'Q36322'
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=' .. janeAusten .. '|birthyear=|deathyear=|dates=}}', '<br />(1775–1817)', {nowiki=1})
	-- Dates not matching.
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=' .. janeAusten .. '|birthyear=1900}}', '<br />(1900–1817)', {nowiki=1})
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=' .. janeAusten .. '|pagetitle=Jane Austen (1770-1817)}}', '<br />(1775–1817)', {nowiki=1})
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=' .. janeAusten .. '|pagetitle=Jane Austen (mechanic)}}', '<br />(1775–1817)', {nowiki=1})
    
	-- Exact birth, century-only death.
	-- FIXME: Wikidata item is no longer representative
	-- local helenaFenwickDale = 'Q20204408'
	-- self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=' .. helenaFenwickDale .. '}}', '<br />(1854 – 20th century)', {nowiki=1})
	
	-- Unknown birth, century-only death.
	-- FIXME: Wikidata item is no longer representative
	-- local johnBarr = 'Q16004141'
	-- self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=' .. johnBarr .. '}}', '<br />(? – 20th century)]', {nowiki=1})
	
	-- Multiple dates of birth. [[Author:David]]
    self:preprocess_equals( '{{#invoke:Author/sandbox|dates|wikidata_id=Q41370}}', '<br />(1039 BCE – 969 BCE)', {nowiki=1} )
    
	-- Multiple death dates in the same year
    local johnKnox = 'Q189937'
    self:preprocess_equals( '{{#invoke:Author/sandbox|dates|wikidata_id='.. johnKnox .. '}}', '<br />(c. 1514 – 1572)', {nowiki=1} )
    
	-- Living person.
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q6279}}', '<br />(1942–)', {nowiki=1})
    
	-- No dates provided.  Manu (Q178744, first human being in Hindu tradition). Only humans are called 'living' by default.
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q178744}}', '', {nowiki=1})
    
	-- 4th century dates, where birth and death are the same.
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q782401}}', '<br />(4th century)', {nowiki=1})
    
	-- Floruit (with birth and death dates = 'unknown').
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q28585286}}', '<br />(fl. 1735)', {nowiki=1})
    
	-- Floruit with no death date.
	-- FIXME: Wikidata item is no longer representative
	-- self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q241132}}', '<br />(fl. c. 509 BCE)', {nowiki=1})
	
	-- First century BCE, where birth and death are the same.
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q670317}}', '<br />(1st century BCE)', {nowiki=1})
    
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q28811762}}', '<br />(fl. 1900s)', {nowiki=1})
    
    -- Multiple floruit dates.
	-- FIXME: Wikidata item is no longer representative
	-- self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q55222075}}', '<br />(fl. 1875–1915)', {nowiki=1})
    
    -- Floruit date more than 110 years ago and no death date.
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q56438002}}', '<br />(fl. 1521)', {nowiki=1})
    
    self:preprocess_equals('{{#invoke:Author/sandbox|dates|wikidata_id=Q34660}}', '<br />(1965–)', {nowiki=1})
end

function p:test_date()
	-- Supplied years.
	self:preprocess_equals('{{#invoke:Author/sandbox|date|year=1820}}', '1820')
	self:preprocess_equals('{{#invoke:Author/sandbox|date|year=c./1820}}', 'c. 1820')
	self:preprocess_equals('{{#invoke:Author/sandbox|date|year=1820s}}', '1820s')
	self:preprocess_equals('{{#invoke:Author/sandbox|date|year=1820?}}', '1820?')
	self:preprocess_equals('{{#invoke:Author/sandbox|date|year=1820/?}}', '1820?')
	self:preprocess_equals('{{#invoke:Author/sandbox|date|year=1932/1933}}', '1932/1933')
	
	-- Approximate birth date.
    self:preprocess_equals('{{#invoke:Author/sandbox|date|type=birth|wikidata_id=Q3276100}}', '19th century')
    self:preprocess_equals('{{#invoke:Author/sandbox|date|type=death|wikidata_id=Q563504}}', '17th century BCE')

	-- Multiple dates of birth, [[Author:Alain de Lille]].
	self:preprocess_equals('{{#invoke:Author/sandbox|date|wikidata_id=Q4313|type=birth}}', '1110s/1114/1115')
	
	-- Exact death date, [[Author:Jane Austen]].
	self:preprocess_equals('{{#invoke:Author/sandbox|date|wikidata_id=Q36322|type=death}}', '1817')
	
	-- Empty death date for living (JK Rowling)
	self:preprocess_equals('{{#invoke:Author/sandbox|date|wikidata_id=Q34660|type=death}}', '' )
	
    -- Empty wikidata_id parameter.
    self:preprocess_equals('{{#invoke:Author/sandbox|date|type=birth|wikidata_id=}}', '')
end

--[=[
Simple test for the wikicode string
]=]
function p:test_categories_wikicode()
	self:preprocess_equals('{{#invoke:Author/sandbox|getCategories|wikidata_id=Q1103678}}',
		'[[Category:1905 births]][[Category:1960 deaths]][[Category:Anthropologists as authors]][[Category:Author pages with gender in Wikidata]][[Category:Author pages without image]][[Category:Authors without initials]][[Category:Male authors]][[Category:Modern authors]][[Category:Sociologists as authors]][[Category:United States authors]]',
		{nowiki=1})
	self:preprocess_equals('{{#invoke:Author/sandbox|getCategories|wikidata_id=Q369724}}',
		'[[Category:1928 births]][[Category:Atheist authors]][[Category:Author pages linking to Wikimedia Commons categories]][[Category:Author pages with Wikidata image]][[Category:Author pages with gender in Wikidata]][[Category:Authors with missing death dates]][[Category:Authors without initials]][[Category:Educators as authors]][[Category:Living authors]][[Category:Lyricists as authors]][[Category:Male authors]][[Category:Mathematicians as authors]][[Category:Modern authors]][[Category:Pianists as authors]][[Category:Singers as authors]][[Category:United States authors]]',
		{nowiki=1})
	self:preprocess_equals('{{#invoke:Author/sandbox|getCategories|wikidata_id=Q474235}}',
		'[[Category:1799 births]][[Category:1888 deaths]][[Category:Author pages linking to Wikimedia Commons categories]][[Category:Author pages with Wikidata image]][[Category:Author pages with gender in Wikidata]][[Category:Authors without initials]][[Category:Early modern authors]][[Category:Educators as authors]][[Category:Male authors]][[Category:Philosophers as authors]][[Category:Transcendentalist authors]][[Category:United States authors]][[Category:authors in EB1911]]',
		{nowiki=1})
end

return p