Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Ordnance Survey coordinates/testcases

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

local before = '<span class="nourlexpansion plainlinks" style="white-space:nowrap">['
local after = ']</span>'
local geohackUrl = 'https://geohack.toolforge.org/geohack.php?'
local geohack = before..geohackUrl
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_many('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | ','}}', {
	{GBos, geohack..pagename..GBloc..'_region:GB_dim:4083m'..' '..GBos..after},
    {GBos..'|rawurl=1', geohackUrl..pagename..GBloc..'_region:GB_dim:4083m'},
	{GBos..'_scale:25000', geohack..pagename..GBloc..'_scale:25000_region:GB'..' '..GBos..after},
	{GBNEos, geohack..pagename..GBNEloc..'_region:GB_dim:41m'..' '..GBNEos..after},
	{IEos, geohack..pagename..IEloc..'_region:IE_dim:4083m'..' '..IEos..after},
	{'439668_1175316 | Crooksetter', geohack..pagename..GBNEloc..'_region:GB Crooksetter'..after},
	{'name=Example title | 439668_1175316 | Crooksetter', geohack..pagename..GBNEloc..'_region:GB&title=Example+title Crooksetter'..after},
    {'439668_1175316_region:GB-SCT_scale:25000 | Crooksetter', geohack..pagename..GBNEloc..'_region:GB-SCT_scale:25000 Crooksetter'..after},
	{'i88888_99999 | The Linbins', geohack..pagename..IENEloc..'_region:IE The Linbins'..after},
	{'i88888_99999_scale:25000 | The Linbins', geohack..pagename..IENEloc..'_scale:25000_region:IE The Linbins'..after},
    {'i88888_99999_scale:25000 | The Linbins | name=Example title',
			geohack..pagename..IENEloc..'_scale:25000_region:IE&title=Example+title The Linbins'..after},
    {'SK 135 733', geohack..pagename..GBloc..'_region:GB_dim:4083m'..' SK 135 733'..after},
    {'123 TQ 456 | Bad', 'Bad'},
    {'busted | Nowhere', 'Nowhere'}},{nowiki=1})
end

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

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

local beforeDirect = '<span class="nourlexpansion" style="white-space:nowrap">['
local osmapsUrl = 'https://explore.osmaps.com/pin?lat='
local osmaps = beforeDirect..osmapsUrl
local GBmapsUrl = 'http://streetmap.co.uk/grid/'
local GBmaps = beforeDirect..GBmapsUrl
local GBlocDirect = '413500_373300'
local GBNElocDirect = '439668_1175316'
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_many('{{#invoke:Ordnance Survey coordinates'..sandbox..' | main | ','|direct=1}}', {
	{GBos, GBmaps..GBlocDirect..'_120 '..GBos..after},
    {GBos..'|rawurl=1', GBmapsUrl..GBlocDirect..'_120'},
	{GBos..'_scale:25000', GBmaps..GBlocDirect..'_115 '..GBos..after},
	{GBNEos, GBmaps..GBNElocDirect..'_106 '..GBNEos..after},
	{IEos, osmaps..IElocDirect..zoom13..osmapsSuffix..' '..IEos..after},
	{'439668_1175316 | Crooksetter', GBmaps..GBNElocDirect..'_120 Crooksetter'..after},
	{'name=Example title | 439668_1175316 | Crooksetter', GBmaps..GBNElocDirect..'_120 Crooksetter'..after},
	{'439668_1175316_region:GB-SCT_scale:25000 | Crooksetter', GBmaps..GBNElocDirect..'_115 Crooksetter'..after},
	{'i88888_99999 | The Linbins', osmaps..IENElocDirect..zoom12..osmapsSuffix..' The Linbins'..after},
	{'i88888_99999_scale:25000 | The Linbins', osmaps..IENElocDirect..zoom14..osmapsSuffix..' The Linbins'..after},
    {'i88888_99999_scale:25000 | The Linbins | name=Example title', osmaps..IENElocDirect..zoom14..osmapsSuffix..' The Linbins'..after},
    {'SK 135 733', GBmaps..GBlocDirect..'_120 SK 135 733'..after},
    {'123 TQ 456 | Bad','Bad'},
    {'busted | Nowhere','Nowhere'}},{nowiki=1})
end

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


function p:test_direct()
    osmaps_test(self,'')
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