local p = require('Module:UnitTests')
local geohack='[https://geohack.toolforge.org/geohack.php?'
local pagename='pagename=Module_talk:Ordnance_Survey_coordinates/testcases¶ms='
local GBloc_lat = '53.256538' -- N
local GBloc_lng = '1.799102' -- W
local GBloc = GBloc_lat..'_N_'..GBloc_lng..'_W'
local IEloc = '53.323786_N_6.246357_W'
local GBNEloc_lat = '60.459657' -- N
local GBNEloc_lng = '1.280627' -- W
local GBNEloc = GBNEloc_lat..'_N_'..GBNEloc_lng..'_W'
local IENEloc = '52.141158_N_9.623702_W'
local GBos = 'SK135733'
local GBos10 = 'SK1350073300'
local GBNEos = 'HU3966875316'
local IEos ='O169318'
function p:test_main()
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | '..GBos..'}}',
geohack..pagename..GBloc..'_region:GB_dim:4083m'..' '..GBos..']')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | '..GBos..'_scale:25000}}',
geohack..pagename..GBloc..'_scale:25000_region:GB'..' '..GBos..']')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | '..GBNEos..'}}',
geohack..pagename..GBNEloc..'_region:GB_dim:41m'..' '..GBNEos..']')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | '..IEos..'}}',
geohack..pagename..IEloc..'_region:IE_dim:4083m'..' '..IEos..']')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | 439668_1175316 | Crooksetter}}',
geohack..pagename..GBNEloc..'_region:GB Crooksetter]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | name=Example title | 439668_1175316 | Crooksetter }}',
geohack..pagename..GBNEloc..'_region:GB&title=Example+title Crooksetter]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | 439668_1175316_region:GB-SCT_scale:25000 | Crooksetter}}',
geohack..pagename..GBNEloc..'_region:GB-SCT_scale:25000 Crooksetter]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | i88888_99999 | The Linbins}}',
geohack..pagename..IENEloc..'_region:IE The Linbins]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | i88888_99999_scale:25000 | The Linbins}}',
geohack..pagename..IENEloc..'_scale:25000_region:IE The Linbins]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | i88888_99999_scale:25000 | The Linbins | name=Example title}}',
geohack..pagename..IENEloc..'_scale:25000_region:IE&title=Example+title The Linbins]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | SK 135 733}}',
geohack..pagename..GBloc..'_region:GB_dim:4083m'..' SK 135 733]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | 123 TQ 456 | Bad}}','Bad')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | main | busted | Nowhere}}','Nowhere')
end
function p:test_main_sandbox()
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | '..GBos..'}}',
geohack..pagename..GBloc..'_region:GB_dim:4083m'..' '..GBos..']')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | '..GBos..'_scale:25000}}',
geohack..pagename..GBloc..'_scale:25000_region:GB'..' '..GBos..']')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | '..IEos..'}}',
geohack..pagename..IEloc..'_region:IE_dim:4083m'..' '..IEos..']')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | 439668_1175316 | Crooksetter}}',
geohack..pagename..GBNEloc..'_region:GB Crooksetter]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | name=Example title | 439668_1175316 | Crooksetter }}',
geohack..pagename..GBNEloc..'_region:GB&title=Example+title Crooksetter]')
self: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]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | i88888_99999 | The Linbins}}',
geohack..pagename..IENEloc..'_region:IE The Linbins]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | i88888_99999_scale:25000 | The Linbins}}',
geohack..pagename..IENEloc..'_scale:25000_region:IE The Linbins]')
self: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]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | SK 135 733}}',
geohack..pagename..GBloc..'_region:GB_dim:4083m'..' SK 135 733]')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | 123 TQ 456 | Bad}}','Bad')
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | main | busted | Nowhere}}','Nowhere')
end
local before = '<span class="plainlinks nourlexpansion" style="white-space: nowrap">'
local after = '</span>'
function p:test_oscoord()
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | oscoord | '..GBos..'}}',
before..geohack..pagename..GBloc..'_region:GB_dim:4083m'..' '..GBos..']'..after)
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | oscoord | '..GBos..'_scale:25000}}',
before..geohack..pagename..GBloc..'_scale:25000_region:GB'..' '..GBos..']'..after)
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | oscoord | '..IEos..'}}',
before..geohack..pagename..IEloc..'_region:IE_dim:4083m'..' '..IEos..']'..after)
end
function p:test_oscoord_sandbox()
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | oscoord | '..GBos..'}}',
before..geohack..pagename..GBloc..'_region:GB_dim:4083m'..' '..GBos..']'..after)
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | oscoord | '..GBos..'_scale:25000}}',
before..geohack..pagename..GBloc..'_scale:25000_region:GB'..' '..GBos..']'..after)
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | oscoord | '..IEos..'}}',
before..geohack..pagename..IEloc..'_region:IE_dim:4083m'..' '..IEos..']'..after)
end
function p:test_to_osgb()
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | WGS2OSGB | '..GBloc_lat..' | -'..GBloc_lng..' }}',GBos10)
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | WGS2OSGB | '..GBloc_lat..' | -'..GBloc_lng..' | 3}}',GBos)
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates | WGS2OSGB | '..GBNEloc_lat..' | -'..GBNEloc_lng..' }}',GBNEos)
self:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' }}',
'{{#invoke:Ordnance Survey coordinates | oscoord | '..GBos10..' }}')
self:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' | scale:25000 |prec=3}}',
'{{#invoke:Ordnance Survey coordinates | oscoord | '..GBos..'_scale:25000}}')
self:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' | scale:25000 |prec=3|name=name}}',
'{{#invoke:Ordnance Survey coordinates | oscoord | '..GBos..'_scale:25000|name=name}}')
end
function p:test_to_osgb_sandbox()
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | WGS2OSGB | '..GBloc_lat..' | -'..GBloc_lng..' }}',GBos10)
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | WGS2OSGB | '..GBloc_lat..' | -'..GBloc_lng..' | 3}}',GBos)
self:preprocess_equals('{{#invoke:Ordnance Survey coordinates/sandbox | WGS2OSGB | '..GBNEloc_lat..' | -'..GBNEloc_lng..' }}',GBNEos)
self:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates/sandbox | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' }}',
'{{#invoke:Ordnance Survey coordinates/sandbox | oscoord | '..GBos10..' }}')
self:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' | scale:25000 |prec=3}}',
'{{#invoke:Ordnance Survey coordinates/sandbox | oscoord | '..GBos..'_scale:25000}}')
self:preprocess_equals_preprocess('{{#invoke:Ordnance Survey coordinates | LL2OS | '..GBloc_lat..' | -'..GBloc_lng..' | scale:25000 |prec=3|name=name}}',
'{{#invoke:Ordnance Survey coordinates/sandbox | oscoord | '..GBos..'_scale:25000|name=name}}')
end
return p