Jump to content

Module:IPAddress/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dcoetzee (talk | contribs) at 03:17, 6 March 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:IPAddress]]. Click talk page to run tests.
local p = require('Module:UnitTests')

function p:test_isIp()
    self:preprocess_equals_many('{{#invoke:IPAddress|isIp|', '}}', {
        {'200.200.200.200', '1'},
        {'200.200.256.200', '0'},
        {'200.200.200.200.', '0'},
        {'200.200.200', '0'},
        {'200.200.200.2d0', '0'},
        {'0.0.0.0', '1'},
        {'255.255.255.255', '1'},
        {'-1.0.0.0', '0'},
        {'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD', '1'}, -- full length
        {'00AB:00002:3008:8CFD:00AB:0002:3008:8CFD', '0'}, -- at most 4 digits per segment
        {':0002:3008:8CFD:00AB:0002:3008:8CFD', '0'}, -- can't remove all 0s from first segment unless using ::
        {'00AB:0002:3008:8CFD:00AB:0002:3008:', '0'}, -- can't remove all 0s from last segment unless using ::
        {'AB:02:3008:8CFD:AB:02:3008:8CFD', '1'}, -- abbreviated
        {'AB:02:3008:8CFD:AB:02:3008:8CFD:02', '0'}, -- too long
        {'AB:02:3008:8CFD::02:3008:8CFD', '1'}, -- correct use of ::
        {'AB:02:3008:8CFD::02:3008:8CFD:02', '0'}, -- too long
        {'AB:02:3008:8CFD::02::8CFD', '0'}, -- can't have two ::s
        {'GB:02:3008:8CFD:AB:02:3008:8CFD', '0'}, -- Invalid character G
        {'::', '1'}, -- unassigned IPv6 address
        {'::1', '1'}, -- loopback IPv6 address
    })
end

return p