Modulo:Wikidata/test: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
|  +test nq |  corretti wikilink dopo aggiornamento formatEntityId | ||
| (27 versioni intermedie di uno stesso utente non sono mostrate) | |||
| Riga 2: local p = require("Module:UnitTests") function p: 	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q503361|", "}}", { 		-- property Riga 10: 		-- 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", "[[ 		-- rank best, ritorna il preferred 		{ "P131|rank=best", "[[ 		-- rank best, in mancanza di preferred ritorna normal 		{ "P94|rank=best", "Malmö fulla vapen.svg" }, 		-- rank + n 		{ "P131|rank=preferred|n=1", "[[ 		{ "P131|rank=preferred|n= 		-- rank non esistente + n => stringa vuota 		{ "P47|rank=preferred|n=1", "" }, 		-- qualifier 		{ "P131|qualifier=P580", "[[ 		-- qualifier + qualifiervalue 		{ "P131|qualifier=P580|qualifiervalue=1º gennaio 2007", "[[ 		-- qualifier + qualifiertype 		{ "P131|qualifier=P580|qualifiertype=latest", "[[ 		-- noqualifier 		{ "P131|noqualifier= 		{ "P190|noqualifier=P580", "[[Kaliningrad]]" }, 		-- qualifieroptnovalue Riga 55 ⟶ 58: 		-- 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", " 		{ "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", " 		{ "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 Riga 88 ⟶ 84: end function p: 	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  		{ " 	}) end function p: 	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: 	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q38|", "}}", { 		-- qualifier + qualifiervalue (item) Riga 115 ⟶ 136: end function p: 	self:preprocess_equals_many("{{Wikidata/Sandbox|from=Q38|", "}}", { 		{ "P38|showqualifiers=P580|rank=normal", "[[ 		-- qualifier multipli 		{ "P38|showqualifiers=P580,P582|rank=normal", "[[ 		-- qualifier non esistenti 		{ "P38|showqualifiers=P580x,P582x|rank=normal", "[[ 	}) end function p: 	self:preprocess_equals_many("{{WikidataQ/Sandbox|from=Q503361|", "}}", { 		-- qualifier non esistente => "" Riga 131 ⟶ 152: 		-- 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" }, Riga 145 ⟶ 169: end function p: 	self:preprocess_equals_many("{{WikidataQ/Sandbox|from=Q68060|", "}}", { 		{ "P856|P407", "[[Lingua italiana|italiano]] e [[Lingua inglese|inglese]]" }, Riga 154 ⟶ 178: end function p: 	self:preprocess_equals_many("{{WikidataIdx/Sandbox|from=Q503361|", "}}", { 		{ "P47|Q186662", "1" }, Riga 160 ⟶ 184: 		{ "P47|Q515706", "3" }, 		-- valore non esistente 		{ "P47|test", " 		-- proprietà non esistente 		{ "P1|Q186662", " 	}) end function p: 	self:preprocess_equals_many("{{WikidataN/Sandbox|from=Q503361|", "}}", { 		{ "P1", "0" }, 		{ "P94", "1" }, 		{ "P131", " 		{ "P47", "10" }, 		-- selezione per rank e qualifier Riga 178 ⟶ 202: end function p: 	self:preprocess_equals_many("{{WikidataLabel/Sandbox|", "}}", { 		-- property 		{ "P17", " 		{ "P17|en", "country" }, 		-- item 		{ "Q503361", "Malmö" }, 		{ "Q503361|en", "Malmö Municipality" } 	}) end function p: 	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]] 		-- { "", "" }, Riga 196 ⟶ 226: 		{ "Q504125", "Copenaghen" }, 		-- senza label e sitelink => label en 		{ " 	}) end function p: 	self:preprocess_equals_many("{{WikidataTipo/Sandbox|", "}}", { 		{ "P10",   "file multimediale su Commons" }, 		{ " 		{ "P3896", "forma geografica" }, 		{ "P625",  "coordinate geografiche" }, 		{ "P2534", "espressione matematica" }, 		{ "P1448", "testo monolingua" }, 		{ "P1082", "quantità" }, 		{ "P229",  "stringa" }, 		{ " 		{ " 		{ " 		{ "P17",   "elemento" }, 		{ " 	}) end function p: 	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" }, Riga 223 ⟶ 265: end function p: 	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]" } Riga 232 ⟶ 274: end function p: 	self:preprocess_equals_many("{{Wikidata/Sandbox|", "}}", { 		-- lunghezza Riga 261 ⟶ 303: end function p: 	self:preprocess_equals_many("{{Wikidata/Sandbox|formatnum=1|", "}}", { 		-- dal modulo stesso Riga 274 ⟶ 316: end function p: 	self:preprocess_equals_many("{{Wikidata/Sandbox|formatnum=1|", "}}", { 		-- dal modulo stesso Riga 292 ⟶ 334: 		{ "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 | |||