Modul:Administrative area/testtilfeller

Fra Wikipedia, den frie encyklopedi


-- Unit tests for [[Module:Administrative area]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local a = require('Module:Administrative area')

function p:test_weird()
    self:preprocess_equals('{{#invoke:Administrative area|parent|Q504977}}', 'Q26589')
end

function p:test_find_qid()
    self:equals( 'fid QID', a._findQID( { 'foo', 'bar', 'baz' } ), nil )
    self:equals( 'fid QID', a._findQID( { 'Q123', 'Q456', 'Q789' } ), 'Q123' )
    self:equals( 'fid QID', a._findQID( { 'Q123', 'bar', 'baz' } ), 'Q123' )
    self:equals( 'fid QID', a._findQID( { 'foo', 'Q123', 'baz' } ), 'Q123' )
    self:equals( 'fid QID', a._findQID( { 'foo', 'bar', 'Q123' } ), 'Q123' )
end

function p:test_find_not_qid()
    self:equals( 'fid not QID', a._findNotQID( { 'foo', 'bar', 'baz' } ), 'foo' )
    self:equals( 'fid not QID', a._findNotQID( { 'Q123', 'Q456', 'Q789' } ), nil )
    self:equals( 'fid not QID', a._findNotQID( { 'Q123', 'bar', 'baz' } ), 'bar' )
    self:equals( 'fid not QID', a._findNotQID( { 'foo', 'Q123', 'baz' } ), 'foo' )
    self:equals( 'fid not QID', a._findNotQID( { 'foo', 'bar', 'Q123' } ), 'foo' )
end

function p:test_load_statements()
	local statements
	statements = a._loadStatements( 'Q48414', 'P94' )
    self:equals_deep( 'load statements, P94, should find something', #statements > 0, true )
	statements = a._loadStatements( 'Q48414', 'P47' )
    self:equals_deep( 'load statements, P47, should find something', #statements > 0, true )
	statements = a._loadStatements( 'Q48414', 'P47', 'P47' )
    self:equals_deep( 'load statements, P47 with backpointer on P47, should find something', #statements > 0, true )
	statements = a._loadStatements( 'Q48414', 'P131' )
    self:equals_deep( 'load statements, P131, should find something', #statements > 0, true )
	statements = a._loadStatements( 'Q48414', 'P131', 'P150' )
    self:equals_deep( 'load statements, P131 with backpointer on P150, should find something', #statements > 0, true )
end

function p:test_entity()
    self:preprocess_equals('{{#invoke:Administrative area|this|Q48414}}', 'Q48414')
    self:preprocess_equals('{{#invoke:Administrative area|parent|Q48414}}', 'Q50617')
    self:preprocess_equals('{{#invoke:Administrative area|nation|Q48414}}', 'Q20')
    self:preprocess_equals('{{#invoke:Administrative area|areas|Q50617}}',
    	'Q486677'
    	.. ' · Q488049'
    	.. ' · Q486713'
    	.. ' · Q108031'
    	.. ' · Q501518'
    	.. ' · Q486704'
    	.. ' · Q488405'
    	.. ' · Q101341'
    	.. ' · Q488395'
    	.. ' · Q488398'
    	.. ' · Q484074'
    	.. ' · Q488401'
    	.. ' · Q486741'
    	.. ' · Q48637'
    	.. ' · Q507499'
    	.. ' · Q484116'
    	.. ' · Q484093'
    	.. ' · Q48414'
    	.. ' · Q488054'
    	.. ' · Q503637'
    	.. ' · Q488439'
    	.. ' · Q48717'
    	.. ' · Q113438'
    	.. ' · Q308420'
    	.. ' · Q316779'
    	.. ' · Q329894')
    self:preprocess_equals('{{#invoke:Administrative area|parts|Q48414}}',
    	'Q19816797'
    	.. ' · Q19816833'
    	.. ' · Q19816834')
    self:preprocess_equals('{{#invoke:Administrative area|neighbors|Q48414}}',
    	'Q484074'
    	.. ' · Q488049'
    	.. ' · Q486741'
    	.. ' · Q484093'
    	.. ' · Q110848'
    	.. ' · Q93703'
    	.. ' · Q483986'
    	.. ' · Q493301')
    self:preprocess_equals('{{#invoke:Administrative area|siblings|Q48414}}',
    	'Q486677'
    	.. ' · Q488049'
    	.. ' · Q486713'
    	.. ' · Q108031'
    	.. ' · Q501518'
    	.. ' · Q486704'
    	.. ' · Q488405'
    	.. ' · Q101341'
    	.. ' · Q488395'
    	.. ' · Q488398'
    	.. ' · Q484074'
    	.. ' · Q488401'
    	.. ' · Q486741'
    	.. ' · Q48637'
    	.. ' · Q507499'
    	.. ' · Q484116'
    	.. ' · Q484093'
    	.. ' · Q48414'
    	.. ' · Q488054'
    	.. ' · Q503637'
    	.. ' · Q488439'
    	.. ' · Q48717'
    	.. ' · Q113438'
    	.. ' · Q308420'
    	.. ' · Q316779'
    	.. ' · Q329894')
    self:preprocess_equals('{{#invoke:Administrative area|nation|Q48414}}', 'Q20')
end

function p:test_layout()
	-- 2. order administrative area, municipality
    self:preprocess_equals('{{#invoke:Administrative area|this|Q48414|verbatim}}', 'Sør-Aurdal')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q48414|title}}', "'''Sør-Aurdal'''")
    self:preprocess_equals('{{#invoke:Administrative area|this|Q48414|link}}', '[[Sør-Aurdal|Sør-Aurdal]]')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q48414|flag}}', '')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q48414|coa}}', 'Sør-Aurdal komm.svg')
	-- 1. order administrative area, county
    self:preprocess_equals('{{#invoke:Administrative area|this|Q50617|verbatim}}', 'Oppland')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q50617|title}}', "'''Oppland'''")
    self:preprocess_equals('{{#invoke:Administrative area|this|Q50617|link}}', '[[Oppland|Oppland]]')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q50617|flag}}', 'Flag of Oppland (Norway).svg')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q50617|coa}}', 'Oppland våpen.svg')
	-- 0. order administrative area, country
    self:preprocess_equals('{{#invoke:Administrative area|this|Q20|verbatim}}', 'Norge')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q20|title}}', "'''Norge'''")
    self:preprocess_equals('{{#invoke:Administrative area|this|Q20|link}}', '[[Norge|Norge]]')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q20|flag}}', 'Flag of Norway.svg')
    self:preprocess_equals('{{#invoke:Administrative area|this|Q20|coa}}', 'Coat of arms of Norway.svg')
end

return p