Module:Tag/testcases

From OpenStreetMap Wiki
Jump to navigation Jump to search
local p = require("Module:UnitTests")

function p:test_tag()
	self:preprocess_equals_many("{{#invoke:Tag|tag|", "}}", {
		-- A single key
		{
			"highway",
			"<bdi style=\"white-space:nowrap\">[[Key:highway|highway]]</bdi>=&#42;",
		},
		-- A specific key/value pair
		{
			"highway|residential",
			"<bdi style=\"white-space:nowrap\">[[Key:highway|highway]]</bdi>=[[Tag:highway=residential|<bdi>residential</bdi>]]",
		},
		-- Padded by whitespace
		{
			" highway | residential ",
			"<bdi style=\"white-space:nowrap\">[[Key:highway|highway]]</bdi>=[[Tag:highway=residential|<bdi>residential</bdi>]]",
		},
		-- A key with a generic, literal value (not hyperlinked)
		{
			"bridge||yes",
			"<bdi style=\"white-space:nowrap\">[[Key:bridge|bridge]]</bdi>=<bdi>yes</bdi>",
		},
		-- A key with a description of value
		{
			"ref||''ref number''",
			"<bdi style=\"white-space:nowrap\">[[Key:ref|ref]]</bdi>=<bdi>''ref number''</bdi>",
		},
		-- Keys and values containing special characters
		{
			"electrified|subkey=before 1927",
			"<bdi style=\"white-space:nowrap\">[[Key:electrified|electrified&#58;before 1927]]</bdi>=&#42;",
		},
		{
			"network|NL:binnenstedelijke_ring",
			"<bdi style=\"white-space:nowrap\">[[Key:network|network]]</bdi>=[[Tag:network=NL:binnenstedelijke_ring|<bdi>NL:binnenstedelijke_ring</bdi>]]",
		},
		{
			"network|US:NY:Saint Lawrence",
			"<bdi style=\"white-space:nowrap\">[[Key:network|network]]</bdi>=[[Tag:network=US:NY:Saint Lawrence|<bdi>US:NY:Saint Lawrence</bdi>]]",
		},
		{
			"name:Zsye|'''&#127482;&#127480;'''",
			"<bdi style=\"white-space:nowrap\">[[Key:name:Zsye|name:Zsye]]</bdi>=[[Tag:name:Zsye='''&#127482;&#127480;'''|<bdi>'''&#127482;&#127480;'''</bdi>]]",
		},
		{
			"height|>20",
			"<bdi style=\"white-space:nowrap\">[[Key:height|height]]</bdi>=<bdi>>20</bdi>",
		},
		{
			"brand|Repair_Caf%C3%A9",
			"<bdi style=\"white-space:nowrap\">[[Key:brand|brand]]</bdi>=<bdi>Repair_Caf%C3%A9</bdi>",
		},
		{
			"brand|Repair_Caf%C3%A9|lang=es",
			"<bdi style=\"white-space:nowrap\">[[ES:Key:brand|brand]]</bdi>=<bdi>Repair_Caf%C3%A9</bdi>",
		},
	})
end

function p:test_tag_multipart_keys()
	self:preprocess_equals_many("{{#invoke:Tag|tag|", "}}", {
		-- Single link to subkey page
		{
			"building:fireproof",
			"<bdi style=\"white-space:nowrap\">[[Key:building:fireproof|building:fireproof]]</bdi>=&#42;",
		},
		-- Single link to main key page
		{
			"addr|subkey=housenumber",
			"<bdi style=\"white-space:nowrap\">[[Key:addr|addr&#58;housenumber]]</bdi>=&#42;",
		},
		-- Multiple links to main key pages
		{
			"oneway|:=bicycle",
			"<bdi style=\"white-space:nowrap\">[[Key:oneway|oneway]]:[[Key:bicycle|bicycle]]</bdi>=&#42;",
		},
		{
			"cycleway|:=right|::=smoothness",
			"<bdi style=\"white-space:nowrap\">[[Key:cycleway|cycleway]]:[[Key:right|right]]:[[Key:smoothness|smoothness]]</bdi>=&#42;",
		},
		{
			"parking|:=right|::=restriction|:::=conditional||charging_only @ (07:00-22:00)",
			"<bdi style=\"white-space:nowrap\">[[Key:parking|parking]]:[[Key:right|right]]:[[Key:restriction|restriction]]:[[Key:conditional|conditional]]</bdi>=<bdi>charging_only @ (07:00-22:00)</bdi>",
		},
	})
end

function p:test_tag_multiple_values()
	self:preprocess_equals_preprocess_many("{{#invoke:Tag|tag|", "}}", "", "", {
		{
			"motor_vehicle|agricultural|;=forestry",
			"<bdi style=\"white-space:nowrap\">[[Key:motor_vehicle|motor_vehicle]]</bdi>=[[Tag:motor_vehicle=agricultural|<bdi>agricultural</bdi>]];[[Tag:motor_vehicle=forestry|<bdi>forestry</bdi>]]",
		},
		{
			"access|agricultural|;=forestry|;;=destination",
			"<bdi style=\"white-space:nowrap\">[[Key:access|access]]</bdi>=[[Tag:access=agricultural|<bdi>agricultural</bdi>]];[[Tag:access=forestry|<bdi>forestry</bdi>]];[[Tag:access=destination|<bdi>destination</bdi>]]",
		},
		{
			"wheelchair||({{TagValue|wheelchair|yes}}/{{TagValue|wheelchair|no}})",
			"<bdi style=\"white-space:nowrap\">[[Key:wheelchair|wheelchair]]</bdi>=<bdi>({{TagValue|wheelchair|yes}}/{{TagValue|wheelchair|no}})</bdi>",
		},
		{
			"motor_vehicle||({{TagValue|motor_vehicle|agricultural}}/{{TagValue|motor_vehicle|forestry}})",
			"<bdi style=\"white-space:nowrap\">[[Key:motor_vehicle|motor_vehicle]]</bdi>=<bdi>({{TagValue|motor_vehicle|agricultural}}/{{TagValue|motor_vehicle|forestry}})</bdi>",
		},
		{
			"access||({{TagValue|access|agricultural}}/{{TagValue|access|forestry}}/{{TagValue|access|destination}})",
			"<bdi style=\"white-space:nowrap\">[[Key:access|access]]</bdi>=<bdi>({{TagValue|access|agricultural}}/{{TagValue|access|forestry}}/{{TagValue|access|destination}})</bdi>",
		},
	})
end

function p:test_tag_external_links()
	self:preprocess_equals_many("{{#invoke:Tag|tag|", "}}", {
		{
			"wikipedia||fr:Paris",
			"<bdi style=\"white-space:nowrap\">[[Key:wikipedia|wikipedia]]</bdi>=[[w:fr:Paris|<bdi>fr:Paris</bdi>]]",
		},
		{
			"wikipedia|subkey=fr||Paris",
			"<bdi style=\"white-space:nowrap\">[[Key:wikipedia|wikipedia&#58;fr]]</bdi>=[[w:fr:Paris|<bdi>Paris</bdi>]]",
		},
		{
			"wikipedia|subkey=en||Paris",
			"<bdi style=\"white-space:nowrap\">[[Key:wikipedia|wikipedia&#58;en]]</bdi>=[[w:en:Paris|<bdi>Paris</bdi>]]",
		},
		{
			"wikidata||Q90",
			"<bdi style=\"white-space:nowrap\">[[Key:wikidata|wikidata]]</bdi>=[[d:Q90|<bdi>Q90</bdi>]]",
		},
		{
			"operator:wikidata||Q90",
			"<bdi style=\"white-space:nowrap\">[[Key:operator:wikidata|operator:wikidata]]</bdi>=[[d:Q90|<bdi>Q90</bdi>]]",
		},
		{
			"wikimedia_commons||[[c:File:Example.svg|File:Example.svg]]",
			"<bdi style=\"white-space:nowrap\">[[Key:wikimedia_commons|wikimedia_commons]]</bdi>=<bdi>[[c:File:Example.svg|File:Example.svg]]</bdi>",
		},
		{
			"website||http://www.paris.fr/",
			"<bdi style=\"white-space:nowrap\">[[Key:website|website]]</bdi>=[http://www.paris.fr/ <bdi style=\"white-space:normal\">http&#58;//www.paris.fr/</bdi>]",
		},
		{
			"website||[https://www.example.com/ https://www.example.com/]",
			"<bdi style=\"white-space:nowrap\">[[Key:website|website]]</bdi>=<bdi>[https://www.example.com/ https://www.example.com/]</bdi>",
		},
	})
end

function p:test_tag_languages()
	self:preprocess_equals_many("{{#invoke:Tag|tag|", "}}", {
		{
			"kl=de|highway|motorway",
			"<bdi style=\"white-space:nowrap\">[[DE:Key:highway|highway]]</bdi>=[[Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
		{
			"highway|vl=de|motorway",
			"<bdi style=\"white-space:nowrap\">[[Key:highway|highway]]</bdi>=[[DE:Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
		{
			"highway|motorway|kl=de|vl=de",
			"<bdi style=\"white-space:nowrap\">[[DE:Key:highway|highway]]</bdi>=[[DE:Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
		{
			"cycleway|:=right|::=smoothness|excellent|kl=de|kl:=de|kl::=de",
			"<bdi style=\"white-space:nowrap\">[[DE:Key:cycleway|cycleway]]:[[DE:Key:right|right]]:[[DE:Key:smoothness|smoothness]]</bdi>=[[Tag:smoothness=excellent|<bdi>excellent</bdi>]]",
		},
	})
end

function p:test_key()
	self:preprocess_equals_many("{{#invoke:Tag|key|", "}}", {
		{
			"landuse",
			"<bdi style=\"white-space:nowrap\">[[Key:landuse|landuse]]</bdi>",
		},
		{
			"landuse|kl=FR",
			"<bdi style=\"white-space:nowrap\">[[FR:Key:landuse|landuse]]</bdi>",
		},
		{
			"landuse|kl=fr",
			"<bdi style=\"white-space:nowrap\">[[FR:Key:landuse|landuse]]</bdi>",
		},
		{
			"electrified|subkey=before 1927",
			"<bdi style=\"white-space:nowrap\">[[Key:electrified|electrified&#58;before 1927]]</bdi>",
		},
		{
			"cycleway|:=right|::=smoothness|kl=de|kl:=de|kl::=de",
			"<bdi style=\"white-space:nowrap\">[[DE:Key:cycleway|cycleway]]:[[DE:Key:right|right]]:[[DE:Key:smoothness|smoothness]]</bdi>",
		},
		{
			"cycleway|:=right|::=smoothness|lang=de",
			"<bdi style=\"white-space:nowrap\">[[DE:Key:cycleway|cycleway]]:[[DE:Key:right|right]]:[[DE:Key:smoothness|smoothness]]</bdi>",
		},
	})
end

function p:test_value()
	self:preprocess_equals_many("{{#invoke:Tag|value|", "}}", {
		{
			"highway",
			"[[Key:highway|<bdi>&#42;</bdi>]]",
		},
		{
			"highway|motorway",
			"[[Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
		{
			"highway|motorway|''type of the way''",
			"[[Tag:highway=motorway|<bdi>''type of the way''</bdi>]]",
		},
		{
			"amenity||shelter",
			"[[Key:amenity#amenity-shelter|<bdi>shelter</bdi>]]",
		},
		{
			"bridge|||yes",
			"[[Key:bridge|<bdi>yes</bdi>]]",
		},
		{
			"ref|||''ref number''",
			"[[Key:ref|<bdi>''ref number''</bdi>]]",
		},
		{
			"type|boundary",
			"[[Relation:boundary|<bdi>boundary</bdi>]]",
		},
	})
end

function p:test_value_named_parameters()
	self:preprocess_equals_many("{{#invoke:Tag|value|", "}}", {
		{
			"link=tag|key=highway|value=motorway",
			"[[Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
		{
			"link=value|key=highway|value=motorway",
			"[[Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
		{
			"link=key|key=highway|value=motorway",
			"[[Key:highway|<bdi>motorway</bdi>]]",
		},
		{
			"link=key#|key=amenity|value=embassy",
			"[[Key:amenity#amenity-embassy|<bdi>embassy</bdi>]]",
		},
		{
			"link=none|key=generator:source|value=biomass",
			"<bdi>biomass</bdi>",
		},
		{
			"link=none|value=biomass",
			"<bdi>biomass</bdi>",
		},
		{
			"lang=ja|link=tag|key=highway|value=motorway",
			"[[JA:Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
		{
			"lang=ja|highway|motorway",
			"[[JA:Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
		{
			"lang=ldn|highway|motorway",
			"[[Ldn:Tag:highway=motorway|<bdi>motorway</bdi>]]",
		},
	})
end

return p