Module:Coordinates/sandbox/testcases

Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Coordinates/sandbox/testcases/doc

Code

-- Unit tests for [[Module:Coordinates]]. Click talk page to run tests.
local p = require('Module:UnitTests/sandbox')

local invoke = mw.title.getCurrentTitle() or ''
if invoke.subpageText == 'testcases' then invoke = mw.title.new(tostring(invoke.baseText), 'Module') end
invoke = '{{#invoke:Coordinates' .. (invoke.subpageText == 'sandbox' and '/sandbox' or '') .. '|'

function p:test_1_getHeading()
    self:preprocess_equals(invoke..'getHeading |heading:NE}}', '45')
    self:preprocess_equals(invoke..'getHeading |heading:NWbW}}', '303.75')
    self:preprocess_equals(invoke..'getHeading |heading:100}}', '100')
    self:preprocess_equals(invoke..'getHeading |heading:-400}}', '320')
    self:preprocess_equals(invoke..'getHeading |heading:100_elevation:1000}}', '100')
    self:preprocess_equals(invoke..'getHeading |elevation:1000_heading:100}}', '100')
    self:preprocess_equals(invoke..'getHeading |elevation:1000_heading:33.33}}', '33.33')
    self:preprocess_equals(invoke..'getHeading |heading:john}}', '')
    self:preprocess_equals(invoke..'getHeading |elevation:1000}}', '')
end

function p:test_2_parseAttribute()
    self:preprocess_equals(invoke..'parseAttribute |heading:100_elevation:1000|heading}}', '100')
    self:preprocess_equals(invoke..'parseAttribute |heading:100_elevation:1000|elevation}}', '1000')
end

function p:test_3_deg2dms()
    self:preprocess_equals(invoke..'deg2dms|199.99|lang=en}}', '199° 59′ 24″')
    self:preprocess_equals(invoke..'deg2dms|199.999|lang=en}}', '199° 59′ 56.4″')
    self:preprocess_equals(invoke..'deg2dms|199.9999|lang=en}}', '199° 59′ 59.64″')
    self:preprocess_equals(invoke..'deg2dms|199.99999|lang=en}}', '199° 59′ 59.964″')
    self:preprocess_equals(invoke..'deg2dms|199.999999|lang=en}}', '199° 59′ 59.996″')
    self:preprocess_equals(invoke..'deg2dms|199.9999995|lang=en}}', '199° 59′ 59.998″')
    self:preprocess_equals(invoke..'deg2dms|199.9999999|lang=en}}', '200° 00′ 00″')
    self:preprocess_equals(invoke..'deg2dms|200.0000001|lang=en}}', '200° 00′ 00″')
    self:preprocess_equals(invoke..'deg2dms|200.0000005|lang=en}}', '200° 00′ 00.002″')
    self:preprocess_equals(invoke..'deg2dms|-90|lang=en}}', '270° 00′ 00″')
    self:preprocess_equals(invoke..'deg2dms|180.5|lang=en}}' , '180° 30′ 00″')
    self:preprocess_equals(invoke..'deg2dms|{{#expr:123.0+45.0/60.0+12.34/3600.0}}|lang=en}}' , '123° 45′ 12.34″')
    self:preprocess_equals(invoke..'deg2dms|{{#expr:123.0+45.0/60.0+12.34/3600.0}}|lang=pl}}' , '123° 45′ 12,34″')
    self:preprocess_equals(invoke..'deg2dms|48.8566667|lang=fr}}' , '48° 51′ 24″')
    self:preprocess_equals(invoke..'deg2dms|48.8566667|lang=fa}}' , '۴۸° ۵۱′ ۲۴″')
    self:preprocess_equals(invoke..'deg2dms|40°|lang=en}}' , '40°')
end

function p:test_4_lat_lon()
	self:preprocess_equals(invoke..'lat_lon |lat=51.48 |lon=0 |lang=en }}','51° 28′ 48″ N, 0° 00′ 00″ E')
	self:preprocess_equals(invoke..'lat_lon |lat=51.48 |lon=0 |lang=ru }}','51° 28′ 48″ с. ш., 0° 00′ 00″ в. д.')
	self:preprocess_equals(invoke..'lat_lon |lat=51.48 |lon=0 |lang=ab }}','51° 28′ 48″ с. ш., 0° 00′ 00″ в. д.')
	self:preprocess_equals(invoke..'lat_lon |lat=51.48 |lon=0 |lang=th }}','51° 28′ 48″ เหนือ, 0° 00′ 00″ ตะวันออก')
	self:preprocess_equals(invoke..'lat_lon |lat=51.48 |lon=0 |lang=ml }}','51° 28′ 48″ വ, 0° 00′ 00″ കി')
	self:preprocess_equals(invoke..'lat_lon |lat=51.48 |lon=0 |lang=xx }}','51° 28′ 48″ N, 0° 00′ 00″ E')
	self:preprocess_equals(invoke..'lat_lon |lat=51.48 |lon=0 |lang=be-tarask }}','51° 28′ 48″ пн. ш., 0° 00′ 00″ з. д.')
	self:preprocess_equals(invoke..'lat_lon |lat= |lon= |lang=en }}','latitude, longitude')
end

function p:test_6_GeoHack_link()
    local pagename = mw.uri.encode(mw.title.getCurrentTitle().prefixedText, 'WIKI')
	self:preprocess_equals(invoke..'GeoHack_link |lat=51.48 |lon=0 }}',
        '<span class="plainlinksneverexpand">[//geohack.toolforge.org/geohack.php?pagename=' .. pagename .. '&params=51.48_N_0_E_globe:Earth_&language=fr 51°&nbsp;28′&nbsp;48″&nbsp;N, 0°&nbsp;00′&nbsp;00″&nbsp;E]</span>',
        {nowiki=1})
	self:preprocess_equals(invoke..'GeoHack_link |lat=51.48 |lon=0 |lang=en }}',
        '<span class="plainlinksneverexpand">[//geohack.toolforge.org/geohack.php?pagename=' .. pagename .. '&params=51.48_N_0_E_globe:Earth_&language=en 51°&nbsp;28′&nbsp;48″&nbsp;N, 0°&nbsp;00′&nbsp;00″&nbsp;E]</span>',
        {nowiki=1})
	self:preprocess_equals(invoke..'GeoHack_link |lat=51.48 |lon=0 |lang=ru }}',
        '<span class="plainlinksneverexpand">[//geohack.toolforge.org/geohack.php?pagename=' .. pagename .. '&params=51.48_N_0_E_globe:Earth_&language=ru 51°&nbsp;28′&nbsp;48″&nbsp;с.&nbsp;ш., 0°&nbsp;00′&nbsp;00″&nbsp;в.&nbsp;д.]</span>',
        {nowiki=1})
	self:preprocess_equals(invoke..'GeoHack_link |lat= |lon=0 |lang=ru }}',
        'latitude, longitude')
end

return p