🇮🇷 Iran Proxy | https://www.wikipedia.org/wiki/Module:Ordnance_Survey_coordinates/testcases
Jump to content

Module:Ordnance Survey coordinates/testcases

From Wikipedia, the free encyclopedia
local p = require('Module:UnitTests')

local geohack = '[https://geohack.toolforge.org/geohack.php?'
local realPagename = 'Module_talk:Ordnance_Survey_coordinates/testcases'
local pagename='pagename=Module_talk:Ordnance_Survey_coordinates/testcases&params='
local GBloc_lat = '53.256538' -- N
local GBloc_lng = '1.799102' -- W
local GBloc = GBloc_lat..'_N_'..GBloc_lng..'_W'
local IEloc_lat = '53.323786' -- N
local IEloc_lng = '6.246357' -- W
local IEloc = IEloc_lat..'_N_'..IEloc_lng..'_W'
local GBNEloc_lat = '60.459657' -- N
local GBNEloc_lng = '1.280627' -- W
local GBNEloc = GBNEloc_lat..'_N_'..GBNEloc_lng..'_W'
local IENEloc_lat = '52.141158' -- N
local IENEloc_lng = '9.623702' -- W
local IENEloc = IENEloc_lat..'_N_'..IENEloc_lng..'_W'
local GBos = 'SK135733'
local GBos10 = 'SK1350073300'
local GBNEos = 'HU3966875316'
local IEos ='O169318'

local function geohack_test(tester,sandbox)
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..GBos..'}}', 
		geohack..pagename..GBloc..'_region:GB_dim:4083m'..' '..GBos..']')
    tester:preprocess_equals('[{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..GBos..'|rawurl=1}}]', 
		geohack..pagename..GBloc..'_region:GB_dim:4083m]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..GBos..'_scale:25000}}',
		geohack..pagename..GBloc..'_scale:25000_region:GB'..' '..GBos..']')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..GBNEos..'}}', 
		geohack..pagename..GBNEloc..'_region:GB_dim:41m'..' '..GBNEos..']')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..IEos..'}}',
		geohack..pagename..IEloc..'_region:IE_dim:4083m'..' '..IEos..']')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | 439668_1175316 | Crooksetter}}',
		geohack..pagename..GBNEloc..'_region:GB Crooksetter]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | name=Example title | 439668_1175316 | Crooksetter }}',
		geohack..pagename..GBNEloc..'_region:GB&title=Example+title Crooksetter]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | 439668_1175316_region:GB-SCT_scale:25000 | Crooksetter}}',
		geohack..pagename..GBNEloc..'_region:GB-SCT_scale:25000 Crooksetter]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | i88888_99999 | The Linbins}}',
		geohack..pagename..IENEloc..'_region:IE The Linbins]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | i88888_99999_scale:25000 | The Linbins}}',
        geohack..pagename..IENEloc..'_scale:25000_region:IE The Linbins]')
    tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | i88888_99999_scale:25000 | The Linbins | name=Example title}}',
        geohack..pagename..IENEloc..'_scale:25000_region:IE&title=Example+title The Linbins]')
    tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | SK 135 733}}', 
		geohack..pagename..GBloc..'_region:GB_dim:4083m'..' SK 135 733]')
    tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | 123 TQ 456 | Bad}}','Bad')
    tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | busted | Nowhere}}','Nowhere')
end

function p:test_main()
    geohack_test(self, '')
end

function p:test_main_sandbox()
    geohack_test(self, '/sandbox')
end

local osmaps = '[https://explore.osmaps.com/pin?lat='
local GBlocDirect = GBloc_lat..'&lon=-'..GBloc_lng
local GBNElocDirect = GBNEloc_lat..'&lon=-'..GBNEloc_lng
local IElocDirect = IEloc_lat..'&lon=-'..IEloc_lng
local IENElocDirect = IENEloc_lat..'&lon=-'..IENEloc_lng
local zoom12 = '&zoom=12'
local zoom13 = '&zoom=13'
local zoom14 = '&zoom=14'
local zoom17 = '&zoom=17'
local osmapsSuffix = '&overlays=&style=Standard&type=2d'

local function osmaps_test(tester, sandbox)
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..GBos..'|direct=1}}', 
        osmaps..GBlocDirect..zoom13..osmapsSuffix..' '..GBos..']')
    tester:preprocess_equals('[{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..GBos..'|rawurl=1|direct=1}}]', 
        osmaps..GBlocDirect..zoom13..osmapsSuffix..']')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..GBos..'_scale:25000|direct=1}}',
		osmaps..GBlocDirect..zoom14..osmapsSuffix..' '..GBos..']')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..GBNEos..'|direct=1}}', 
		osmaps..GBNElocDirect..zoom17..osmapsSuffix..' '..GBNEos..']')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | '..IEos..'|direct=1}}',
		osmaps..IElocDirect..zoom13..osmapsSuffix..' '..IEos..']')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | 439668_1175316 | Crooksetter|direct=1}}',
		osmaps..GBNElocDirect..zoom12..osmapsSuffix..' Crooksetter]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | name=Example title | 439668_1175316 | Crooksetter |direct=1}}',
		osmaps..GBNElocDirect..zoom12..osmapsSuffix..' Crooksetter]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | 439668_1175316_region:GB-SCT_scale:25000 | Crooksetter|direct=1}}',
		osmaps..GBNElocDirect..zoom14..osmapsSuffix..' Crooksetter]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | i88888_99999 | The Linbins|direct=1}}',
		osmaps..IENElocDirect..zoom12..osmapsSuffix..' The Linbins]')
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | i88888_99999_scale:25000 | The Linbins|direct=1}}',
        osmaps..IENElocDirect..zoom14..osmapsSuffix..' The Linbins]')
    tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | i88888_99999_scale:25000 | The Linbins | name=Example title|direct=1}}',
        osmaps..IENElocDirect..zoom14..osmapsSuffix..' The Linbins]')
    tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | SK 135 733|direct=1}}', 
		osmaps..GBlocDirect..zoom13..osmapsSuffix..' SK 135 733]')
    tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | 123 TQ 456 | Bad|direct=1}}','Bad')
    tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | busted | Nowhere|direct=1}}','Nowhere')
end

function p:test_direct_sandbox()
    osmaps_test(self,'/sandbox')
end


function p:test_direct()
    osmaps_test(self,'')
end


local before = '<span class="plainlinks nourlexpansion" style="white-space: nowrap">'
local after = '</span>'

local function oscoord_test(tester, sandbox)
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | oscoord | '..GBos..'}}', 
		before..geohack..pagename..GBloc..'_region:GB_dim:4083m'..' '..GBos..']'..after)
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | oscoord | '..GBos..'_scale:25000}}',
		before..geohack..pagename..GBloc..'_scale:25000_region:GB'..' '..GBos..']'..after)
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | oscoord | '..IEos..'}}',
		before..geohack..pagename..IEloc..'_region:IE_dim:4083m'..' '..IEos..']'..after)
end


function p:test_oscoord()
    oscoord_test(self, '')
end

function p:test_oscoord_sandbox()
    oscoord_test(self,'/sandbox')
end

local function osgb_test(tester, sandbox)
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | WGS2OSGB | '..GBloc_lat..' | -'..GBloc_lng..' }}',GBos10)
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | WGS2OSGB | '..GBloc_lat..' | -'..GBloc_lng..' | 3}}',GBos)
	tester:preprocess_equals('{{#invoke:Ordnance Survey coordinates'..sandbox..' | WGS2OSGB | '..GBNEloc_lat..' | -'..GBNEloc_lng..' }}',GBNEos)
	tester:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates'..sandbox..' | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' }}',
		'{{#invoke:Ordnance Survey coordinates'..sandbox..' | oscoord | '..GBos10..' }}')
	tester:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates'..sandbox..' | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' | scale:25000 |prec=3}}',
		'{{#invoke:Ordnance Survey coordinates'..sandbox..' | oscoord | '..GBos..'_scale:25000}}')
	tester:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates'..sandbox..' | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' | scale:25000 |prec=3|name=name}}',
		'{{#invoke:Ordnance Survey coordinates'..sandbox..' | oscoord | '..GBos..'_scale:25000|name=name}}')
end

function p:test_to_osgb()
    osgb_test(self,'')
end

function p:test_to_osgb_sandbox()
    osgb_test(self,'/sandbox')
end

return p