Modulo:Wikidata/test

-- Unit tests per [[Modulo:Wikidata]]. Cliccare sulla pagina di discussione per eseguire i test.
local p = require("Module:UnitTests")

function p:test_getProperty()
	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q503361|", "}}", {
		-- property
		{ "P94", "Malmö fulla vapen.svg" },
		-- property non esistente => ""
		{ "P1", "" },
		-- value
		{ "P94|test", "test" },
		-- wd=no
		{ "P94|test|wd=no", "test" },
		{ "P94|wd=no", "" },
		-- statement multipli
		{ "P47", "[[Burlöv|comune di Burlöv]], [[Staffanstorp (comune)|comune di Staffanstorp]], [[Svedala (comune)|Svedala]], [[Vellinge (comune)|Vellinge]], Copenaghen, [[Tårnby]], [[Dragør]], [[Solrød]], [[Greve (Danimarca)|Greve]] e [[Kävlinge (comune)|Kävlinge]]" },
		-- n
		{ "P47|n=1", "[[Burlöv|comune di Burlöv]]" },
		{ "P47|n=2", "[[Staffanstorp (comune)|comune di Staffanstorp]]" },
		{ "P47|n=3", "[[Svedala (comune)|Svedala]]" },
		-- rank
		{ "P131|rank=preferred", "[[contea della Scania]] e [[Scania (provincia)|Scania]]" },
		-- rank best, ritorna il preferred
		{ "P131|rank=best", "[[contea della Scania]] e [[Scania (provincia)|Scania]]" },
		-- rank best, in mancanza di preferred ritorna normal
		{ "P94|rank=best", "Malmö fulla vapen.svg" },
		-- rank + n
		{ "P131|rank=preferred|n=1", "[[contea della Scania]]" },
		{ "P131|rank=preferred|n=3", "" },
		-- rank non esistente + n => stringa vuota
		{ "P47|rank=preferred|n=1", "" },
		-- qualifier
		{ "P131|qualifier=P580", "[[contea della Scania]]" },
		-- qualifier + qualifiervalue
		{ "P131|qualifier=P580|qualifiervalue=1º gennaio 2007", "[[contea della Scania]]" },
		-- qualifier + qualifiertype
		{ "P131|qualifier=P580|qualifiertype=latest", "[[contea della Scania]]" },
		-- noqualifier
		{ "P131|noqualifier=P580", "[[Scania (provincia)|Scania]]" },
		{ "P190|noqualifier=P580", "[[Kaliningrad]]" },
		-- qualifieroptnovalue
		{ "P131|qualifieroptnovalue=P582|qualifiervalue=31 dicembre 2006|rank=normal", "" },

		-- datavalue.type = wikibase-entityid (con label e sitelink mancanti in italiano => label en)
		{ "P361", "Malmö metropolitan area" },
		-- datavalue.type = wikibase-entityid (con label ma sitelink mancante in italiano => stringa)
		{ "P47|n=5", "Copenaghen" },
		-- datavalue.type = wikibase-entityid (con sitelink ma label mancante in italiano => [[sitelink]])
		-- todo
		-- datavalue.type = wikibase-entityid (con label e sitelink in italiano => [[sitelink|label]])
		{ "P31", "[[Comuni della Svezia|comune svedese]]" },
		-- datavalue.type = string
		{ "P1566", "2692965" },
		-- datavalue.type = globecoordinate
		{ "P625", "55.583333333333, 13.033333333333" },
		-- datavalue.type = monolingualtext
		{ "P1813", "Malmö" },

		-- separator
		{ "P47|separator=/", "[[Burlöv|comune di Burlöv]]/[[Staffanstorp (comune)|comune di Staffanstorp]]/[[Svedala (comune)|Svedala]]/[[Vellinge (comune)|Vellinge]]/Copenaghen/[[Tårnby]]/[[Dragør]]/[[Solrød]]/[[Greve (Danimarca)|Greve]] e [[Kävlinge (comune)|Kävlinge]]" },
		-- conjunction
		{ "P47|conjunction=+", "[[Burlöv|comune di Burlöv]], [[Staffanstorp (comune)|comune di Staffanstorp]], [[Svedala (comune)|Svedala]], [[Vellinge (comune)|Vellinge]], Copenaghen, [[Tårnby]], [[Dragør]], [[Solrød]], [[Greve (Danimarca)|Greve]]+[[Kävlinge (comune)|Kävlinge]]" },
		-- separator e conjunction
		{ "P47|separator=/|conjunction=+", "[[Burlöv|comune di Burlöv]]/[[Staffanstorp (comune)|comune di Staffanstorp]]/[[Svedala (comune)|Svedala]]/[[Vellinge (comune)|Vellinge]]/Copenaghen/[[Tårnby]]/[[Dragør]]/[[Solrød]]/[[Greve (Danimarca)|Greve]]+[[Kävlinge (comune)|Kävlinge]]" },
		-- list
		{ "P94|list=1", "Malmö fulla vapen.svg" },
		{ "P47|list=1", "<ul><li>[[Burlöv|comune di Burlöv]]</li><li>[[Staffanstorp (comune)|comune di Staffanstorp]]</li><li>[[Svedala (comune)|Svedala]]</li><li>[[Vellinge (comune)|Vellinge]]</li><li>Copenaghen</li><li>[[Tårnby]]</li><li>[[Dragør]]</li><li>[[Solrød]]</li><li>[[Greve (Danimarca)|Greve]]</li><li>[[Kävlinge (comune)|Kävlinge]]</li></ul>" },
		{ "P94|list=1|rank=deprecated", "" },
		-- orderedlist
		{ "P94|orderedlist=1", "Malmö fulla vapen.svg" },
		{ "P47|orderedlist=1", "<ol><li>[[Burlöv|comune di Burlöv]]</li><li>[[Staffanstorp (comune)|comune di Staffanstorp]]</li><li>[[Svedala (comune)|Svedala]]</li><li>[[Vellinge (comune)|Vellinge]]</li><li>Copenaghen</li><li>[[Tårnby]]</li><li>[[Dragør]]</li><li>[[Solrød]]</li><li>[[Greve (Danimarca)|Greve]]</li><li>[[Kävlinge (comune)|Kävlinge]]</li></ol>" },
		{ "P94|orderedlist=1|rank=deprecated", "" },
		-- coord=latitude
		{ "P625|coord=latitude", "55.583333333333" },
		-- coord=longitude
		{ "P625|coord=longitude", "13.033333333333" },
		-- coord=globe
		{ "P625|coord=globe", "http://www.wikidata.org/entity/Q2" },
		-- formatting=raw con type wikibase-entityid 
		{ "P36|formatting=raw", "Q2211" },
		-- showprop
		{ "P17|showprop=P298", "SWE" }
})
end

function p:test_pattern()
	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q503361|", "}}", {
		-- pattern
		{ "P94|pattern=$1: il nome del file è $1", "Malmö fulla vapen.svg: il nome del file è Malmö fulla vapen.svg" },
		-- pattern + value
		{ "P94|Test.png|pattern=$1: il nome del file è $1", "Test.png: il nome del file è Test.png" },
		-- pattern con utilizzo di %
		{ "P94|simbolo %20|pattern=test: $1", "test: simbolo %20" },
		-- pattern con più statement
		{ "P47|pattern=($1)", "([[Burlöv|comune di Burlöv]]), ([[Staffanstorp (comune)|comune di Staffanstorp]]), ([[Svedala (comune)|Svedala]]), ([[Vellinge (comune)|Vellinge]]), (Copenaghen), ([[Tårnby]]), ([[Dragør]]), ([[Solrød]]), ([[Greve (Danimarca)|Greve]]) e ([[Kävlinge (comune)|Kävlinge]])" },
		-- se pattern non restituisce nulla per un determinato elemento, esso è rimosso dai risultati
		{ "P47|pattern=\\{\\{#switch:$1{{!}}[[Burlöv{{!}}comune di Burlöv]]={{!}}#default=($1)\\}\\} ", "([[Staffanstorp (comune)|comune di Staffanstorp]]), ([[Svedala (comune)|Svedala]]), ([[Vellinge (comune)|Vellinge]]), (Copenaghen), ([[Tårnby]]), ([[Dragør]]), ([[Solrød]]), ([[Greve (Danimarca)|Greve]]) e ([[Kävlinge (comune)|Kävlinge]])" },
	})
end

function p:test_language()
	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q30|", "}}", {
		{ "P1813|includelang=en", "USA, America e United States" },
		{ "P1813|includelang=en,pt", "USA, EUA, America e United States" },
		{ "P1451|excludelang=ca|rank=normal", "E Pluribus Unum" }
	})
end

function p:test_time()
	self:preprocess_equals_many("{{Wikidata/Sandbox|", "}}", {
		{ "from=Q38|P571", "2 giugno 1946" },
		{ "from=Q38|P571|time=year", "1946" },
		{ "from=Q38|P571|time=month", "giugno 1946" },
		{ "from=Q38|P571|time=day", "2 giugno 1946" },
		{ "from=Q38|P571|time=precision", "11" },
		{ "from=Q38|P571|time=calendarmodel", "http://www.wikidata.org/entity/Q1985727" },
		{ "from=Q38|P571|formatting=raw", "+1946-06-02T00:00:00Z" },
		{ "from=Q1407|P569", "16 novembre 42 a.C." },
		{ "from=Q1407|P569|time=year", "42 a.C." },
		{ "from=Q1407|P569|time=month", "novembre 42 a.C." },
		{ "from=Q1407|P569|time=day", "16 novembre 42 a.C." },
		{ "from=Q1407|P569|formatting=raw", "-0042-11-16T00:00:00Z" },
		{ "from=Q1407|P570", "16 marzo 37" },
		{ "from=Q1407|P570|time=year", "37" },
		{ "from=Q1407|P570|time=month", "marzo 37" },
		{ "from=Q1407|P570|time=day", "16 marzo 37" },
		{ "from=Q1407|P570|formatting=raw", "+0037-03-16T00:00:00Z" }
	})
end

function p:test_qualifiervalue()
	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q38|", "}}", {
		-- qualifier + qualifiervalue (item)
		{ "P47|qualifier=P805|qualifiervalue=Q1991288", "[[Francia]]" }
	})
end

function p:test_showqualifiers()
	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q38|", "}}", {
		{ "P38|showqualifiers=P580|rank=normal", "[[lira italiana]] (2 giugno 1946)" },
		-- qualifier multipli
		{ "P38|showqualifiers=P580,P582|rank=normal", "[[lira italiana]] (2 giugno 1946, 28 febbraio 2002)" },
		-- qualifier non esistenti
		{ "P38|showqualifiers=P580x,P582x|rank=normal", "[[lira italiana]]" }
	})
end

function p:test_getQualifier()
	self:preprocess_equals_many("{{WikidataQ/Sandbox|from=Q503361|", "}}", {
		-- qualifier non esistente => ""
		{ "P131|P1", "" },
		-- value
		{ "P131|P582|test", "test" },
		-- wd=no
		{ "P131|P582|test|wd=no", "test" },
		{ "P131|P582|wd=no", "" },
		-- datavalue.type=time
		{ "P131|P580", "1º gennaio 2007" },
		{ "P131|P582|rank=normal", "31 dicembre 2006" },
		-- datavalue.type=time e formatting=raw
		{ "P131|P580|formatting=raw", "+2007-01-01T00:00:00Z" },
		-- datavalue.type=time e time=precision
		{ "P131|P580|time=precision", "11" },
		-- datavalue.type=time e time=calendarmodel
		{ "P131|P580|time=calendarmodel", "http://www.wikidata.org/entity/Q1985727" },
		-- pattern
		{ "P131|P582|rank=normal|pattern=($1)", "(31 dicembre 2006)" }
	})
end

function p:test_qualifier_nq()
	self:preprocess_equals_many("{{WikidataQ/Sandbox|from=Q68060|", "}}", {
		{ "P856|P407", "[[Lingua italiana|italiano]] e [[Lingua inglese|inglese]]" },
		{ "P856|P407|nq=1", "[[Lingua italiana|italiano]]" },
		{ "P856|P407|nq=2", "[[Lingua inglese|inglese]]" },
		{ "P856|P407|nq=3", "" }
	})
end

function p:test_indexOf()
	self:preprocess_equals_many("{{WikidataIdx/Sandbox|from=Q503361|", "}}", {
		{ "P47|Q186662", "1" },
		{ "P47|Q504609", "2" },
		{ "P47|Q515706", "3" },
		-- valore non esistente
		{ "P47|test", "" },
		-- proprietà non esistente
		{ "P1|Q186662", "" },
	})
end

function p:test_N()
	self:preprocess_equals_many("{{WikidataN/Sandbox|from=Q503361|", "}}", {
		{ "P1", "0" },
		{ "P94", "1" },
		{ "P131", "2" },
		{ "P47", "10" },
		-- selezione per rank e qualifier
		{ "P131|rank=normal", "1" },
		{ "P190|qualifier=P580|qualifiervalue=1990", "1" }
	})
end

function p:test_getLabel()
	self:preprocess_equals_many("{{WikidataLabel/Sandbox|", "}}", {
		-- property
		{ "P17", "Paese" },
		{ "P17|en", "country" },
		-- item
		{ "Q503361", "Malmö" },
		{ "Q503361|en", "Malmö Municipality" }
	})
end

function p:test_getLink()
	self:preprocess_equals_many("{{WikidataLink/Sandbox|", "}}", {
		-- sitelink e label => [[sitelink|label]]
		{ "Q503361", "[[Malmö (comune)|Malmö]]" },
		-- sitelink = label => [[label]]
		{ "Q1067", "[[Dante Alighieri]]" },
		-- sitelink = label (iniziale minuscola) => [[label]]
		{ "Q5369", "[[baseball]]" },
		-- solo sitelink => [[sitelink]]
		-- { "", "" },
		-- solo label => label
		{ "Q504125", "Copenaghen" },
		-- senza label e sitelink => label en
		{ "Q1573432", "HeroCraft" }
	})
end

function p:test_getDatatype()
	self:preprocess_equals_many("{{WikidataTipo/Sandbox|", "}}", {
		{ "P10",   "file multimediale su Commons" },
		{ "P214",  "identificativo esterno" },
		{ "P3896", "forma geografica" },
		{ "P625",  "coordinate geografiche" },
		{ "P2534", "espressione matematica" },
		{ "P1448", "testo monolingua" },
		{ "P1082", "quantità" },
		{ "P229",  "stringa" },
		{ "P4179", "tabular data" },
		{ "P569",  "data e ora" },
		{ "P856",  "URL" },
		{ "P17",   "elemento" },
		{ "P1659", "proprietà" }
	})
end

function p:test_getId()
	self:preprocess_equals_many("{{WikidataId/Sandbox|", "}}", {
		{ "Italia", "Q38" },
		-- test redirect non collegato a un elemento Wikidata
		{ "Repubblica Italiana", "Q38" },
		-- test redirect collegato a un elemento
		{ "Millimetro", "Q174789" }
	})
end

function p:test_instanceOf()
	self:preprocess_equals_many("{{WikidataIstanza/Sandbox|from=Q503361|", "}}", {
		{ "Q127448", "1" },
		{ "Q747074", "" }
	})
end

function p:test_extlink()
	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q8038|extlink=1|", "}}", {
		{ "P856", "<div style=\"word-break: break-all;\">[https://www.gimp.org www.gimp.org]</div>" },
		{ "P856|http://www.mediawiki.org", "<div style=\"word-break: break-all;\">[http://www.mediawiki.org www.mediawiki.org]</div>" },
		{ "P856|test", "test" },
		{ "P856|[http://www.mediawiki.org test]", "[http://www.mediawiki.org test]" }
	})
end

function p:test_convert()
	self:preprocess_equals_many("{{Wikidata/Sandbox|", "}}", {
		-- lunghezza
		{ "from=Q12418|P2049|unit=millimetro", "530" },
		{ "from=Q12418|P2049|unit=centimetro", "53" },
		{ "from=Q12418|P2049|unit=piede", "1.738845144357" },
		{ "from=Q12418|P2049|unit=iarda", "0.57961504811899" },
		{ "from=Q12418|P2049|unit=metro", "0.53" },
		{ "from=Q12418|P2049|unit=chilometro", "0.00053" },
		{ "from=Q12418|P2049|unit=miglio", "0.00032932673188579" },
		{ "from=Q12418|P2049|unit=miglio nautico", "0.00028617710583153" },
		-- area
		{ "from=Q643|P2053|unit=metro quadrato", "74000000000" },
		{ "from=Q643|P2053|unit=chilometro quadrato", "74000" },
		{ "from=Q643|P2053|unit=miglio quadro", "28571.559732141" },
		-- solo showunit (simbolo unità ottenuto da Wikidata)
		{ "from=Q12418|P2049|showunit=1", "53 cm" },
		-- solo showunit e gradi d'arco (non utilizza lo spazio)
		{ "from=Q2|P2248|showunit=1", "114.20783°" },
		-- unit + showunit (simbolo unità ottenuto dal modulo Conversione)
		{ "from=Q12418|P2049|unit=centimetro|showunit=1", "53 cm" },
		-- showunitlink
		{ "from=Q12418|P2049|showunit=1|showunitlink=1", "53 [[Centimetro|cm]]" },
		{ "from=Q12418|P2049|unit=centimetro|showunit=1|showunitlink=1", "53 [[metro|cm]]" },
		-- formatduration
		{ "from=Q111|P2147|formatduration=1", "1 giorno, 37 minuti e 22 secondi" },
	})
end

function p:test_formatnum()
	self:preprocess_equals_many("{{Wikidata/Sandbox|formatnum=1|", "}}", {
		-- dal modulo stesso
		{ "from=Q643|P2053", "74\194\160000" },
		{ "from=Q5830|P2050", "79,8" },
		-- dal modulo stesso con simbolo unità di misura
		{ "from=Q5830|P2050|showunit=1", "79,8 m" },		
		-- tramite il modulo:Conversione
		{ "from=Q5830|P2050|unit=cm", "7\194\160980" },
		{ "from=Q5830|P2050|unit=km", "0,0798" },
	})
end

function p:test_rounding()
	self:preprocess_equals_many("{{Wikidata/Sandbox|formatnum=1|", "}}", {
		-- dal modulo stesso
		{ "from=Q3710|P2370|rounding=0", "0" },
		{ "from=Q3710|P2370|rounding=1", "0,3" },
		{ "from=Q3710|P2370|rounding=2", "0,3" },
		{ "from=Q3710|P2370|rounding=3", "0,305" },
		{ "from=Q3710|P2370|rounding=4", "0,3048" },
		-- dal modulo stesso con simbolo unità di misura
		{ "from=Q3710|P2370|rounding=0|showunit=1", "0 m" },
		{ "from=Q3710|P2370|rounding=1|showunit=1", "0,3 m" },
		{ "from=Q3710|P2370|rounding=2|showunit=1", "0,3 m" },
		{ "from=Q3710|P2370|rounding=3|showunit=1", "0,305 m" },
		{ "from=Q3710|P2370|rounding=4|showunit=1", "0,3048 m" },
		-- tramite il modulo:Conversione
		{ "from=Q3710|P2370|rounding=0|unit=cm", "30" },
		{ "from=Q3710|P2370|rounding=1|unit=cm", "30,5" },
		{ "from=Q3710|P2370|rounding=2|unit=cm", "30,48" }
	})
end

function p:test_getProperty_nil()
	local mWikidata = require('Modulo:Wikidata/sandbox')
	-- _getProperty restituisce nil:
	-- se non è collegata a un elemento Wikidata
	self:preprocess_equals(tostring(mWikidata._getProperty({ 'P94' })), 'nil')
	-- se i risultati sono 0 perché l'elemento non esiste
	self:preprocess_equals(tostring(mWikidata._getProperty({ 'P94', from = 'Q6' })), 'nil')
	-- se i risultati sono 0 perché la proprietà non esiste in quell'elemento
	self:preprocess_equals(tostring(mWikidata._getProperty({ 'P1447', from = 'Q503361' })), 'nil')
	-- se i risultati sono 0 perché non ci sono valori della proprietà che soddisfano i criteri
	self:preprocess_equals(tostring(mWikidata._getProperty({ 'P18', from = 'Q503361', n = 2 })), 'nil')
end

function p:test_getClaims_nil_or_empty()
	local mWikidata = require('Modulo:Wikidata/sandbox')
	-- _getClaims restituisce nil se non è collegata un elemento Wikidata
	self:preprocess_equals(tostring(mWikidata._getClaims('P94')), 'nil')

	-- _getClaims restituisce una sequence Lua vuota se:
	-- l'elemento Wikidata specificato non esiste
	self:preprocess_equals(tostring(#mWikidata._getClaims('P94', { from = 'Q6' })), '0')
	-- l'elemento Wikidata non ha la proprietà specificata
	self:preprocess_equals(tostring(#mWikidata._getClaims('P1447', { from = 'Q503361' })), '0')
	-- non ci sono valori della proprietà specificata che soddisfano i criteri
	self:preprocess_equals(tostring(#mWikidata._getClaims('P18', { from = 'Q503361', n = 2 })), '0')
end

function p:test_snaktype()
	self:preprocess_equals_many("{{Wikidata/Sandbox|", "}}", {
		-- test snaktype novalue
		{ "from=Q7207|P40", "''nessun valore''" },
		-- test snaktype somevalue		
		{ "from=Q24039104|P569", "''valore sconosciuto''" },
		-- test parametro snaktype
		{ "from=Q7207|P40|snaktype=novalue", "''nessun valore''" },
		{ "from=Q7207|P40|snaktype=value", "" },
		{ "from=Q7207|P31|snaktype=value", "umano" },
		{ "from=Q24039104|P569|snaktype=somevalue", "''valore sconosciuto''" },
		{ "from=Q24039104|P569|snaktype=value", "" },
		{ "from=Q24039104|P31|snaktype=value", "umano" }
	})
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.