Module:Adjacent stations/testcases

-- Unit tests for Module:Adjacent stations. Click talk page to run tests.

--[[

When adding new tests make sure to test all possible combinations. A system can have one line or many; A line can have one type, many or none; A system or line can use defaults; A line or type can use a title with or without a short name; A system, line, or type can use an icon or an icon format or can not use any;

]]--

local p = require('Module:UnitTests')

function p:test_01_icon self:preprocess_equals_sandbox_many('{{#invoke:Adjacent stations', 'icon', {		-- Icon for a system with an icon. Use .		{'system=testcases/Test module', },		{'testcases/Test module', },

-- Icon for a system without an icon. Show no icon. {'system=San Diego Trolley', ''}, --TODO: use test module instead. {'San Diego Trolley', ''}, --TODO: use test module instead.

-- Icon for a line with an icon. Use. {'system=testcases/Test module|line=line with title', ''}, {'testcases/Test module|line with title', ''},

-- Icon for a type without icon, belonging to a line with an icon. Use. {'system=testcases/Test module|line=line with type|type=type with title', ''}, {'testcases/Test module|line with type|type with title', ''},

-- Icon for a type with an icon, belonging to a line with an icon. Use. {'system=testcases/Test module|line=line with type|type=icon type', ''}, {'testcases/Test module|line with type|icon type', ''},

-- Icon for a type with an icon, belonging to a line without an icon. Use. {'system=testcases/Test module|line=line without icon with type|type=type with icon', ''}, {'testcases/Test module|line without icon with type|type with icon', ''},

-- Icon for a type without an icon, belonging to a line without an icon. Use. {'system=testcases/Test module|line=line without icon with type|type=type without icon', ''}, {'testcases/Test module|line without icon with type|type without icon', ''},

-- _default icon for lines. --TODO: add expected. {'Antwerp tram|1', ''}, --TODO: use test module instead. -- _default icon for lines using alias. --TODO: add expected. {'Antwerp tram|line 1', ''}, --TODO: use test module instead.

-- Override _default icon for lines with icon specified. --TODO: add expected. {'São Paulo Metropolitan Trains|13-AE', ''}, --TODO: use test module instead.

-- Sole line default. --TODO: add expected. {'Taiwan High Speed Rail', ''}, --TODO: use test module instead.

-- Override icon for line when "icon format" is set. --TODO: add expected. {'Brampton Transit|Brampton Transit', ''}, --TODO: use test module instead. }) end

-- -- Need to create tests for: --- ["system icon format"] --- line_type['icon format'] --- data['type icon format'] --- data['line icon format'] -- inline --- route without link --- route with link --- croute without link --- croute with link --- xroute without link --- xroute with link --- legend -- function p:test_02_icon_format self:preprocess_equals_sandbox_many('{{#invoke:Adjacent stations', 'icon', {		-- Icon for a line with "system icon format" = "route". --TODO: add expected.		{'system=Brussels Metro|line=1', ' 1  ',}, --TODO: use test module instead.		{'Brussels Metro|1', '  1  ',}, --TODO: use test module instead.

-- Icon for a line with "system icon format" = "croute". --TODO: add expected. {'system=Vorarlberg S-Bahn|line=1', ' S1  '}, --TODO: use test module instead. {'Vorarlberg S-Bahn|1', ' S1  '},		 --TODO: use test module instead.

-- Icon for a line with "line icon format" = "link". --TODO: add expected. {'system=MTR|line=Island', '      '}, --TODO: use test module instead. {'MTR|Island', '      '}, --TODO: use test module instead.

-- Icon for a line with "line icon format" = "link" using alias. --TODO: add expected. {'system=MTR|line=isl', '      '}, --TODO: use test module instead. {'MTR|isl', '      '},		 --TODO: use test module instead.

-- Icon for a line with "line icon format" = "route". --TODO: add expected. {'system=Shenzhen Metro|line=1', ' 1  '}, --TODO: use test module instead. {'Shenzhen Metro|1', ' 1  '}, --TODO: use test module instead.

-- Icon for a line with "line icon format" = "croute". --TODO: add expected. {'system=MTR Light Rail|line=505', ' 505  '}, --TODO: use test module instead. {'MTR Light Rail|505', ' 505  '}, --TODO: use test module instead. }) end

-- Tests for icon format in lines. function p:test_03_icon_format_lines self:preprocess_equals_sandbox_many('{{#invoke:Adjacent stations', 'icon', {		-- Icon for a line with "icon format" = "link", a linked title, and no short name. --TODO: add expected.		{'system=testcases/Test module|line=link line', '      '},		{'testcases/Test module|link line', '      '},

-- Icon for a line with "icon format" = "route", a linked title, and no short name. Use "route" style with. {'system=testcases/Test module|line=route line', ' 501 Züm Queen  '}, {'testcases/Test module|route line', ' 501 Züm Queen  '},

-- Icon for a line with "icon format" = "croute", a linked title, and no short name. Use "croute" style with. {'system=testcases/Test module|line=croute line', ' 501 Züm Queen  '}, {'testcases/Test module|croute line', ' 501 Züm Queen  '},

-- Icon for a line with "icon format" = "xroute", a linked title, and no short name. Use "xroute" style with. {'system=testcases/Test module|line=xroute line', ' 501 Züm Queen  '}, {'testcases/Test module|xroute line', ' 501 Züm Queen  '},

-- Icon for a line with "icon format" = "legend", a linked title, and no short name. Use line "legend" style with. {'system=testcases/Test module|line=legend line', '    501 Züm Queen '}, {'testcases/Test module|legend line', '    501 Züm Queen '},

-- Icon for a line with "icon format" = "link", a linked title, and a short name. --TODO: add expected. {'system=testcases/Test module|line=link line with linked title and short name', '      '}, {'testcases/Test module|link line with linked title and short name', '      '},

-- Icon for a line with "icon format" = "route", a linked title, and a short name. Use "route" style with |. {'system=testcases/Test module|line=route line with linked title and short name', ' route line linked short name  '}, {'testcases/Test module|route line with linked title and short name', ' route line linked short name  '},

-- Icon for a line with "icon format" = "croute", a linked title, and a short name. Use "croute" style with |. {'system=testcases/Test module|line=croute line with linked title and short name', ' croute line linked short name  '}, {'testcases/Test module|croute line with linked title and short name', ' croute line linked short name  '},

-- Icon for a line with "icon format" = "xroute", a linked title, and a short name. Use "xroute" style with |. {'system=testcases/Test module|line=xroute line with linked title and short name', ' xroute line linked short name  '}, {'testcases/Test module|xroute line with linked title and short name', ' xroute line linked short name  '},

-- Icon for a line with "icon format" = "legend", a linked title, and a short name. --TODO: add expected. {'system=testcases/Test module|line=legend line with linked title and short name', '    501 Züm Queen '}, {'testcases/Test module|legend line with linked title and short name', '    501 Züm Queen '},

-- Icon for a line with "icon format" = "link", an unlinked title, and a short name. --TODO: add expected. {'system=testcases/Test module|line=link line with unlinked title and short name', '      '}, {'testcases/Test module|link line with unlinked title and short name', '      '},

-- Icon for a line with "icon format" = "route", an unlinked title, and a short name. Use "route" style with. {'system=testcases/Test module|line=route line with unlinked title and short name', 'route line unlinked short name '}, {'testcases/Test module|route line with unlinked title and short name', 'route line unlinked short name '},

-- Icon for a line with "icon format" = "croute", an unlinked title, and a short name. Use "croute" style with. {'system=testcases/Test module|line=croute line with unlinked title and short name', 'croute line unlinked short name '}, {'testcases/Test module|croute line with unlinked title and short name', 'croute line unlinked short name '},

-- Icon for a line with "icon format" = "xroute", an unlinked title, and a short name. Use "xroute" style with. {'system=testcases/Test module|line=xroute line with unlinked title and short name', 'xroute line unlinked short name '}, {'testcases/Test module|xroute line with unlinked title and short name', 'xroute line unlinked short name '},

-- Icon for a line with "icon format" = "legend", an unlinked title, and a short name. --TODO: add expected. {'system=testcases/Test module|line=legend line with unlinked title and short name', '    501 Züm Queen '}, {'testcases/Test module|legend line with unlinked title and short name', '    501 Züm Queen '}, }) end

-- Tests for icon format in types. function p:test_04_icon_format_types self:preprocess_equals_sandbox_many('{{#invoke:Adjacent stations', 'icon', {		-- Icon for a type with "icon format" = "link" and a line with an icon and a linked title.		{'system=testcases/Test module|line=line with linked title and type|type=link type', '      '},		{'testcases/Test module|line with linked title and type|link type', '      '},

-- Icon for a type with "icon format" = "route". {'system=testcases/Test module|line=line with linked title and type|type=route type', ' route type  '}, {'testcases/Test module|line with linked title and type|route type', ' route type  '},

-- Icon for a type with "icon format" = "croute". {'system=testcases/Test module|line=line with linked title and type|type=croute type', ' croute type  '}, {'testcases/Test module|line with linked title and type|croute type', ' croute type  '},

-- Icon for a type with "icon format" = "xroute". {'system=testcases/Test module|line=line with linked title and type|type=xroute type', ' xroute type  '}, {'testcases/Test module|line with linked title and type|xroute type', ' xroute type  '},

-- Icon for a type with "icon format" = "legend". {'system=testcases/Test module|line=line with linked title and type|type=legend type', '    linked line title – legend title '}, {'testcases/Test module|line with linked title and type|legend type', '    linked line title – legend title '},

-- Icon for a type with "icon format" = "link", a linked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=link type with linked title and short name', '      '}, {'testcases/Test module|line with linked title and type|link type with linked title and short name', '      '},

-- Icon for a type with "icon format" = "route", a linked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=route type with linked title and short name', ' route type  '}, {'testcases/Test module|line with linked title and type|route type with linked title and short name', ' route type  '},

-- Icon for a type with "icon format" = "croute", a linked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=croute type with linked title and short name', ' croute type  '}, {'testcases/Test module|line with linked title and type|croute type with linked title and short name', ' croute type  '},

-- Icon for a type with "icon format" = "xroute", a linked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=xroute type with linked title and short name', ' xroute type  '}, {'testcases/Test module|line with linked title and type|xroute type with linked title and short name', ' xroute type  '},

-- Icon for a type with "icon format" = "legend", a linked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=legend type with linked title and short name', '    linked line title – 501 Züm Queen '}, {'testcases/Test module|line with linked title and type|legend type with linked title and short name', '    linked line title – 501 Züm Queen '},

-- Icon for a type with "icon format" = "link", an unlinked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=link type with unlinked title and short name', '      '}, {'testcases/Test module|line with linked title and type|link type with unlinked title and short name', '      '},

-- Icon for a type with "icon format" = "route", an unlinked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=route type with unlinked title and short name', ' route type  '}, {'testcases/Test module|line with linked title and type|route type with unlinked title and short name', ' route type  '},

-- Icon for a type with "icon format" = "croute", an unlinked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=croute type with unlinked title and short name', ' croute type  '}, {'testcases/Test module|line with linked title and type|croute type with unlinked title and short name', ' croute type  '},

-- Icon for a type with "icon format" = "xroute", an unlinked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=xroute type with unlinked title and short name', ' xroute type  '}, {'testcases/Test module|line with linked title and type|xroute type with unlinked title and short name', ' xroute type  '},

-- Icon for a type with "icon format" = "legend", an unlinked title, and a short name. {'system=testcases/Test module|line=line with linked title and type|type=legend type with unlinked title and short name', ' <span class="legend-color" style="display:inline-block;width:1.5em;height:1.5em;margin:1px 0;border:1px solid black;background-color:#ff0000">   linked line title – 501 Züm Queen '}, {'testcases/Test module|line with linked title and type|legend type with unlinked title and short name', ' <span class="legend-color" style="display:inline-block;width:1.5em;height:1.5em;margin:1px 0;border:1px solid black;background-color:#ff0000">   linked line title – 501 Züm Queen '},

}) end

function p:test_05_errors_maybe self:preprocess_equals_sandbox_many('{{#invoke:Adjacent stations', 'icon', {

--		Tests for a type of a line without a title.		-- --TODO: update type line names -- Icon for a type with "icon format" = "link". {'system=testcases/Test module|line=line without title with type|type=link type', '      '}, {'testcases/Test module|line without title with type|link type', '      '},

-- Icon for a type with "icon format" = "route". {'system=testcases/Test module|line=line without title with type|type=route type', ' route type  '}, {'testcases/Test module|line without title with type|route type', ' route type  '},

-- Icon for a type with "icon format" = "croute". {'system=testcases/Test module|line=line without title with type|type=croute type', ' croute type  '}, {'testcases/Test module|line without title with type|croute type', ' croute type  '},

-- Icon for a type with "icon format" = "xroute". {'system=testcases/Test module|line=line without title with type|type=xroute type', ' xroute type  '}, {'testcases/Test module|line without title with type|xroute type', ' xroute type  '},

-- Icon for a type with "icon format" = "legend". {'system=testcases/Test module|line=line without title with type|type=legend type', ' <span class="legend-color" style="display:inline-block;width:1.5em;height:1.5em;margin:1px 0;border:1px solid black;background-color:#ff0000">   Taoyuan Airport MRT – legend title '}, {'testcases/Test module|line without title with type|legend type', ' <span class="legend-color" style="display:inline-block;width:1.5em;height:1.5em;margin:1px 0;border:1px solid black;background-color:#ff0000">   Taoyuan Airport MRT – legend title '},

-- Icon for a type with "icon format" = "link" and a short name. {'system=testcases/Test module|line=line without title with type|type=link type with linked title and short name', '      '}, {'testcases/Test module|line without title with type|link type with linked title and short name', '      '},

-- Icon for a type with "icon format" = "route" and a short name. {'system=testcases/Test module|line=line without title with type|type=route type with linked title and short name', ' route type  '}, {'testcases/Test module|line without title with type|route type with linked title and short name', ' route type  '},

-- Icon for a type with "icon format" = "croute" and a short name. {'system=testcases/Test module|line=line without title with type|type=croute type with linked title and short name', ' croute type  '}, {'testcases/Test module|line without title with type|croute type with linked title and short name', ' croute type  '},

-- Icon for a type with "icon format" = "xroute" and a short name. {'system=testcases/Test module|line=line without title with type|type=xroute type with linked title and short name', ' xroute type  '}, {'testcases/Test module|line without title with type|xroute type with linked title and short name', ' xroute type  '},

-- Icon for a type with "icon format" = "legend" and a short name. {'system=testcases/Test module|line=line without title with type|type=legend type with linked title and short name', ' <span class="legend-color" style="display:inline-block;width:1.5em;height:1.5em;margin:1px 0;border:1px solid black;background-color:#ff0000">   Taoyuan Airport MRT – 501 Züm Queen '}, {'testcases/Test module|line without title with type|legend type with linked title and short name', ' <span class="legend-color" style="display:inline-block;width:1.5em;height:1.5em;margin:1px 0;border:1px solid black;background-color:#ff0000">   Taoyuan Airport MRT – 501 Züm Queen '},

-- Icon for a type with "icon format" = "link" and a short name. {'system=testcases/Test module|line=line without title with type|type=link type with unlinked title and short name', '      '}, {'testcases/Test module|line without title with type|link type with unlinked title and short name', '      '},

-- Icon for a type with "icon format" = "route" and a short name. {'system=testcases/Test module|line=line without title with type|type=route type with unlinked title and short name', '  route type  '}, {'testcases/Test module|line without title with type|route type with unlinked title and short name', '  route type  '},

-- Icon for a type with "icon format" = "croute" and a short name. {'system=testcases/Test module|line=line without title with type|type=croute type with unlinked title and short name', '  croute type  '}, {'testcases/Test module|line without title with type|croute type with unlinked title and short name', '  croute type  '},

-- Icon for a type with "icon format" = "xroute" and a short name. {'system=testcases/Test module|line=line without title with type|type=xroute type with unlinked title and short name', '  xroute type  '}, {'testcases/Test module|line without title with type|xroute type with unlinked title and short name', '  xroute type  '},

-- Icon for a type with "icon format" = "legend" and a short name. {'system=testcases/Test module|line=line without title with type|type=legend type with unlinked title and short name', ' <span class="legend-color" style="display:inline-block;width:1.5em;height:1.5em;margin:1px 0;border:1px solid black;background-color:#ff0000">   Taoyuan Airport MRT – 501 Züm Queen '}, {'testcases/Test module|line without title with type|legend type with unlinked title and short name', ' <span class="legend-color" style="display:inline-block;width:1.5em;height:1.5em;margin:1px 0;border:1px solid black;background-color:#ff0000">   Taoyuan Airport MRT – 501 Züm Queen '},

}) end

function p:test_06_icon_with_name self:preprocess_equals_sandbox_many('{{#invoke:Adjacent stations', 'icon', {		-- Icon for a system with an icon and a title. Use and .		{'system=testcases/Test module|name=y', ' VR Group'},		{'testcases/Test module|name=y', ' VR Group'},

-- Icon for a system without an icon and a title. Use system title. {'system=San Diego Trolley|name=y', 'San Diego Trolley'}, --TODO: use test module instead. {'San Diego Trolley|name=y', 'San Diego Trolley'}, --TODO: use test module instead.

-- Icon for a line with an icon format and a title. --TODO expected {'system=MTR|line=Island|name=y', '      Island line'}, --TODO: use test module instead. {'MTR|Island|name=y', '      Island line'}, --TODO: use test module instead.

-- Icon for a line with an icon format and a title using an alias. --TODO expected {'system=MTR|line=isl|name=y', '      Island line'}, --TODO: use test module instead. {'MTR|isl|name=y', '      Island line'}, --TODO: use test module instead.

--		Tests for lines with title variations.		--

-- Icon and name for a line with an icon and a title. Use and. {'system=testcases/Test module|line=line with title|name=y', ' Green Line'}, {'testcases/Test module|line with title|name=y', ' Green Line'},

-- Icon and name for a line with a linked title and a short name. Use <short name>. {'system=testcases/Test module|line=line with linked title and shortname|name=y', ' linked short name'}, {'testcases/Test module|line with linked title and shortname|name=y', ' linked short name'},

-- Icon and name for a line with an unlinked title and a short name. Use. {'system=testcases/Test module|line=line with unlinked title and shortname|name=y', ' unlinked short name'}, {'testcases/Test module|line with unlinked title and shortname|name=y', ' unlinked short name'},

-- Icon and name for line without title and with short name. Use. {'system=testcases/Test module|line=line without title and with shortname|name=y', ' short name'}, {'testcases/Test module|line without title and with shortname|name=y', ' short name'},

-- Icon and name for line without title. Use. {'system=testcases/Test module|line=line without title|name=y', ' VR Group'}, {'testcases/Test module|line without title|name=y', ' VR Group'},

--		Tests for lines without icons and title variations.		-- -- Icon and name for line without icon and with title. Use line title. {'system=testcases/Test module|line=line without icon and with title|name=y', ' Green Line'}, {'testcases/Test module|line without icon and with title|name=y', ' Green Line'},

-- Icon and name for line without icon and with linked title and short name. Use line short name. {'system=testcases/Test module|line=line without icon and with linked title and shortname|name=y', ' linked short name'}, {'testcases/Test module|line without icon and with linked title and shortname|name=y', ' linked short name'},

-- Icon and name for line without icon and with unlinked title and short name. Use line short name. {'system=testcases/Test module|line=line without icon and with unlinked title and shortname|name=y', ' unlinked short name'}, {'testcases/Test module|line without icon and with unlinked title and shortname|name=y', ' unlinked short name'},

-- Icon and name for line without icon and title and with short name. Use line short name. {'system=testcases/Test module|line=line without icon and title and with shortname|name=y', ' short name'}, {'testcases/Test module|line without icon and title and with shortname|name=y', ' short name'},

-- Icon and name for line without icon, title and short name. Use system title. {'system=testcases/Test module|line=line without icon title and shortname|name=y', ' VR Group'}, {'testcases/Test module|line without icon title and shortname|name=y', ' VR Group'},

--		Tests for line with title and types with title variations.		--

-- Icon and name for line with title and icon, and type with title. Use line title – type title. {'system=testcases/Test module|line=line with type|type=type with title|name=y', ' Taoyuan Airport MRT – type with title'}, {'testcases/Test module|line with type|type with title|name=y', ' Taoyuan Airport MRT – type with title'},

-- Icon and name for line with title and icon, and type without title. Use line title. {'system=testcases/Test module|line=line with type|type=type without title|name=y', ' Taoyuan Airport MRT'}, {'testcases/Test module|line with type|type without title|name=y', ' Taoyuan Airport MRT'},

-- Icon and name for line with title and icon, and type with linked title and short name. Use line title – type short name. {'system=testcases/Test module|line=line with type|type=type with linked title and shortname|name=y', ' Taoyuan Airport MRT – linked type short name'}, {'testcases/Test module|line with type|type with linked title and shortname|name=y', ' Taoyuan Airport MRT – linked type short name'},

-- Icon and name for line with title and icon, and type with unlinked title and short name. Use line title – type short name. {'system=testcases/Test module|line=line with type|type=type with unlinked title and shortname|name=y', ' Taoyuan Airport MRT – unlinked type short name'}, {'testcases/Test module|line with type|type with unlinked title and shortname|name=y', ' Taoyuan Airport MRT – unlinked type short name'},

-- Icon and name for line with title and icon, and type with without title and with short name. Use line title – type short name. {'system=testcases/Test module|line=line with type|type=line without title and with shortname|name=y', ' Taoyuan Airport MRT – type short name'}, {'testcases/Test module|line with type|line without title and with shortname|name=y', ' Taoyuan Airport MRT – type short name'},

--		Tests for line without title and types with title variations.		--

-- Icon and name for line without title and icon, and type with title. Use type title. {'system=testcases/Test module|line=line without title with type|type=type with title|name=y', ' type with title'}, {'testcases/Test module|line without title with type|type with title|name=y', ' type with title'},

-- Icon and name for line without title and icon, and type without title. Use system title. {'system=testcases/Test module|line=line without title with type|type=type without title|name=y', ' VR Group'}, {'testcases/Test module|line without title with type|type without title|name=y', ' VR Group'},

-- Icon and name for line without title and icon, and type with linked title and short name. Use type short name. {'system=testcases/Test module|line=line without title with type|type=type with linked title and shortname|name=y', ' linked type short name'}, {'testcases/Test module|line without title with type|type with linked title and shortname|name=y', ' linked type short name'},

-- Icon and name for line without title and icon, and type with unlinked title and short name. Use type short name. {'system=testcases/Test module|line=line without title with type|type=type with unlinked title and shortname|name=y', ' unlinked type short name'}, {'testcases/Test module|line without title with type|type with unlinked title and shortname|name=y', ' unlinked type short name'},

-- Icon and name for line without title and icon, and type with without title and with short name. Use type short name. {'system=testcases/Test module|line=line without title with type|type=line without title and with shortname|name=y', ' type short name'}, {'testcases/Test module|line without title with type|line without title and with shortname|name=y', ' type short name'},

}) end

-- Need tests for: --- |size= – image size, expressed as width (15px), height (x15px) or both if necessary (15x15px). --- |link= – image link (full page name) --- |alt= – alt text --- |bold= – setting for some types of text-based icon; default is "yes" for all of those types

--- line without title, type without title - using named and unnamed. Named params seems to ignore error.

-- defaults -- overriding - if a line has an icon set to "", it overrides any other setting? overrides only the _default?

function p:test_07_errors -- No module. self:preprocess_equals('{{#invoke:Adjacent stations/sandbox|icon|system=Taipei|R}}', '') -- No type for line. self:preprocess_equals('{{#invoke:Adjacent stations/sandbox|icon|system=testcases/Test module|line=line with type|type=222222}}', ' Lua error: Type "22222" for line "line with type" not in Module:Adjacent stations/testcases/Test module. ') end

return p