सामग्री पर जाएँ

मॉड्यूल:Author/testcases

विकिस्रोत से

"इस मॉड्यूल हेतु प्रलेख मॉड्यूल: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 = '[[श्रेणी:Authors with missing birth dates]][[श्रेणी:Authors with missing death dates]]'
    self:preprocess_equals('{{#invoke:Author|dates}}', out, {nowiki=1})

	-- Manual dates.
	out = '<br />(Manual dates)[[श्रेणी:Authors with missing birth dates]][[श्रेणी:Authors with missing death dates]][[श्रेणी: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)[[श्रेणी:1904 births]][[श्रेणी:1960s deaths]][[श्रेणी:Authors with non-numeric death dates]]'
		.. '[[श्रेणी:Authors with override birth dates]][[श्रेणी:Authors with override dates]][[श्रेणी:Authors with override death dates]][[श्रेणी: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)[[श्रेणी:1810 births]][[श्रेणी:1890 deaths]][[श्रेणी:Authors with override birth dates]][[श्रेणी:Authors with override death dates]][[श्रेणी: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)[[श्रेणी:1810 births]][[श्रेणी:1890 deaths]][[श्रेणी:Authors with approximate death dates]][[श्रेणी:Authors with override birth dates]]'
		.. '[[श्रेणी:Authors with override death dates]][[श्रेणी: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 – ?)[[श्रेणी:1810 births]][[श्रेणी:? deaths]][[श्रेणी:Authors with approximate birth dates]][[श्रेणी:Authors with non-numeric death dates]][[श्रेणी:Authors with override birth dates]]'
		.. '[[श्रेणी:Authors with override death dates]][[श्रेणी:Early modern authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|birthyear=ca/1810|deathyear=?}}', out, {nowiki=1})

	-- Multiple birth dates.
	out = '<br />(1932/1933–)[[श्रेणी:1932 births]][[श्रेणी:1933 births]]'
		.. '[[श्रेणी:Authors with approximate birth dates]][[श्रेणी:Authors with missing death dates]][[श्रेणी:Authors with override birth dates]][[श्रेणी: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)[[श्रेणी:1775 births]][[श्रेणी:1817 deaths]][[श्रेणी: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)[[श्रेणी:1775 births]][[श्रेणी:1817 deaths]][[श्रेणी:1900 births]]'
		.. '[[श्रेणी:Authors with birth dates differing from Wikidata]][[श्रेणी:Authors with override birth dates]][[श्रेणी:Early modern authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. janeAusten .. '|birthyear=1900}}', out, {nowiki=1})
	out = '<br />(1775–1817)[[श्रेणी:1775 births]][[श्रेणी:1817 deaths]][[श्रेणी:Authors with title-date mismatches]][[श्रेणी:Early modern authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. janeAusten .. '|pagetitle=Jane Austen (1770-1817)}}', out, {nowiki=1})
	out = '<br />(1775–1817)[[श्रेणी:1775 births]][[श्रेणी:1817 deaths]][[श्रेणी:Early modern authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. janeAusten .. '|pagetitle=Jane Austen (mechanic)}}', out, {nowiki=1})

	-- Exact birth, century-only death.
	local helenaFenwickDale = 'Q20204408'
	out = '<br />(1854 – 20th century)[[श्रेणी:1854 births]][[श्रेणी:20th century deaths]][[श्रेणी:Authors with approximate death dates]][[श्रेणी:Early modern authors]][[श्रेणी:Modern authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. helenaFenwickDale .. '}}', out, {nowiki=1})

	-- Unknown birth, century-only death.
	local johnBarr = 'Q16004141'
	out = '<br />(? – 20th century)[[श्रेणी:20th century deaths]][[श्रेणी:Authors with approximate death dates]][[श्रेणी:Authors with unknown birth dates]][[श्रेणी:Modern authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=' .. johnBarr .. '}}', out, {nowiki=1})

	-- Multiple dates of birth. [[Author:David]]
	out = '<br />(1040 BCE/1039 BCE – 970 BCE/969 BCE)[[श्रेणी:1039 BCE births]][[श्रेणी:1040 BCE births]][[श्रेणी:969 BCE deaths]][[श्रेणी:970 BCE deaths]][[श्रेणी:Ancient authors]]'
    self:preprocess_equals( '{{#invoke:Author|dates|wikidata_id=Q41370}}', out, {nowiki=1} )
    local johnKnox = 'Q189937' -- Multiple death dates in the same year
	out = '<br />(c. 1514 – 1572)[[श्रेणी:1514 births]][[श्रेणी:1572 deaths]][[श्रेणी:Authors with approximate birth dates]][[श्रेणी:Renaissance authors]]'
    self:preprocess_equals( '{{#invoke:Author|dates|wikidata_id='.. johnKnox .. '}}', out, {nowiki=1} )

	-- Living person.
	out = '<br />(1942–)[[श्रेणी:1942 births]][[श्रेणी:Authors with missing death dates]][[श्रेणी:Living authors]][[श्रेणी: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 = '[[श्रेणी:Authors with missing birth dates]][[श्रेणी: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)[[श्रेणी:4th century births]][[श्रेणी:4th century deaths]][[श्रेणी:Ancient authors]][[श्रेणी:Authors with approximate birth dates]][[श्रेणी: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)[[श्रेणी:Authors with floruit dates]][[श्रेणी:Authors with unknown birth dates]][[श्रेणी:Authors with unknown death dates]][[श्रेणी:Early modern authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q28585286}}', out, {nowiki=1})

	-- Floruit with no death date.
	out = '<br />(fl. c. 509 BCE)[[श्रेणी:Ancient authors]][[श्रेणी:Authors with approximate floruit dates]][[श्रेणी:Authors with floruit dates]][[श्रेणी:Authors with missing birth dates]][[श्रेणी: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)[[श्रेणी:1st century BCE births]][[श्रेणी:1st century BCE deaths]][[श्रेणी:Ancient authors]][[श्रेणी:Authors with approximate birth dates]][[श्रेणी:Authors with approximate death dates]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q670317}}', out, {nowiki=1})

	out = '<br />(fl. 1900s)[[श्रेणी:Authors with approximate floruit dates]][[श्रेणी:Authors with floruit dates]][[श्रेणी:Authors with unknown birth dates]][[श्रेणी:Authors with unknown death dates]][[श्रेणी:Modern authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q28811762}}', out, {nowiki=1})
    
    -- Multiple floruit dates.
	out = '<br />(fl. 1875–1915)[[श्रेणी:Authors with approximate floruit dates]][[श्रेणी:Authors with floruit dates]][[श्रेणी:Authors with unknown birth dates]][[श्रेणी:Authors with unknown death dates]][[श्रेणी: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)[[श्रेणी:Authors with floruit dates]][[श्रेणी:Authors with missing birth dates]][[श्रेणी:Authors with missing death dates]][[श्रेणी:Renaissance authors]]'
    self:preprocess_equals('{{#invoke:Author|dates|wikidata_id=Q56438002}}', out, {nowiki=1})

    out = '<br />(1965–)[[श्रेणी:1965 births]][[श्रेणी:Authors with missing death dates]][[श्रेणी:Living authors]][[श्रेणी: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}}', '19वीं सदी')
    self:preprocess_equals('{{#invoke:Author|date|type=death|wikidata_id=Q563504}}', '17वीं सदी ईसा पूर्व')

	-- 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

--[=[
Tests for if we can dig out categories
]=]
function p:test_categories_list()
	local cases = {
		{
			wikidataId = 'Q1103678',
			expectedCats = {
				'अमेरिकी लेखक',
				'मानवविज्ञानी',
				'समाजविज्ञानी'
			}
		},
		{
			wikidataId = 'Q474235',
			expectedCats = {
				'अमेरिकी लेखक',
				'दार्शनिक',
				'शिक्षाविद',
				'ट्रांसेंडेंटलिस्ट्स'
			}
		}
	}
	
	for _, c in pairs( cases ) do
		local entity = mw.wikibase.getEntity( c.wikidataId )
		local actualCats = Author.categoriesList( entity )
		
		local label = c.wikidataId
		if entity.labels.en then
			label = '[[wikidata:' .. c.wikidataId .. '|' .. entity.labels.en.value .. ']]'
		end
		
		self:equals_deep( label, actualCats, c.expectedCats )
	end
end

--[=[
Simple test for the wikicode string
]=]
function p:test_categories_wikicode()
	self:preprocess_equals('{{#invoke:Author|categories|wikidata_id=Q1103678}}',
		'[[श्रेणी:अमेरिकी लेखक]]\n[[श्रेणी:मानवविज्ञानी]]\n[[श्रेणी:समाजविज्ञानी]]\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=}}',
		'[[श्रेणी:Authors without initials]]',
		{nowiki=1}
	) ]=]

	-- Has Wikidata with family name (J.K. Rowling).
	self:preprocess_equals(
		'{{#invoke:Author|lastInitial|wikidata_id=Q34660|last_initial=}}',
		'[[विकिस्रोत:लेखक-Ro|लेखक अनुक्रमाणिका: Ro]][[श्रेणी:लेखक-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=क}}',
		'[[विकिस्रोत:लेखक-क|लेखक अनुक्रमाणिका: क]][[श्रेणी:लेखक-क]][[श्रेणी:अनुपलब्ध आद्याक्षर श्रेणी वाले लेखक पृष्ठ]]',
		{nowiki=1}
	)

    -- {{disambiguation}} template override
	self:preprocess_equals(
		'{{#invoke:Author|lastInitial|wikidata_id=Q34660|last_initial=!NO_INITIALS}}',
		'',
		{nowiki=1}
	)
end

return p