Module:IPAddress/testcases
| This is the test cases page for the module Module:IPAddress. Results of the test cases. |
-- 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/sandbox|isIp|', '}}', {
{'200.200.200.200', '4'},
{' 200.200.200.200', ''}, -- whitespace not currently allowed
{'200.200.200.200 ', ''}, -- whitespace not currently allowed
{'200.200.256.200', ''},
{'200.200.200.200.', ''},
{'200.200.200', ''},
{'200.200.200.2d0', ''},
{'0.0.0.0', '4'},
{'00.00.00.00', ''}, -- according to talkpage, leading zeroes unacceptable.
{'100.100.020.100', ''}, -- according to talkpage, leading zeroes unacceptable.
{'255.255.255.255', '4'},
{'-1.0.0.0', ''},
{'200000000000000000000000000000000000000000000000000000000000000000000000000000.200.200.200', ''},
{'00000000000005.10.10.10', ''},
{'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD', '6'}, -- full length
{'00ab:0002:3008:8cfd:00ab:0002:3008:8cfd', '6'}, -- lowercase
{'00aB:0002:3008:8cFd:00Ab:0002:3008:8cfD', '6'}, -- mixed case
{'00AB:00002:3008:8CFD:00AB:0002:3008:8CFD', ''}, -- at most 4 digits per segment
{':0002:3008:8CFD:00AB:0002:3008:8CFD', ''}, -- can't remove all 0s from first segment unless using ::
{'00AB:0002:3008:8CFD:00AB:0002:3008:', ''}, -- can't remove all 0s from last segment unless using ::
{'AB:02:3008:8CFD:AB:02:3008:8CFD', '6'}, -- abbreviated
{'AB:02:3008:8CFD:AB:02:3008:8CFD:02', ''}, -- too long
{'AB:02:3008:8CFD::02:3008:8CFD', '6'}, -- correct use of ::
{'AB:02:3008:8CFD::02:3008:8CFD:02', ''}, -- too long
{'AB:02:3008:8CFD::02::8CFD', ''}, -- can't have two ::s
{'GB:02:3008:8CFD:AB:02:3008:8CFD', ''}, -- Invalid character G
{'::', '6'}, -- unassigned IPv6 address
{'::1', '6'}, -- loopback IPv6 address
{'0::', '6'}, -- another name for unassigned IPv6 address
{'0::0', '6'}, -- another name for unassigned IPv6 address
{'2:::3', ''}, -- illegal: three colons
})
end
function p:test_isIpV4Range()
self:preprocess_equals_many('{{#invoke:IPAddress/sandbox|isIpV4Range|', '}}', {
{'200.200.200.200', '0'},
{'200.200.200.0/28', '1'},
{'0.0.0.0', '0'},
{'0.0.0.0/28', '1'},
{'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD', '0'},
{'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD/64', '0'},
{'0::0/64', '0'},
{'0::0', '0'},
})
end
function p:test_isIpV6Range()
self:preprocess_equals_many('{{#invoke:IPAddress/sandbox|isIpV6Range|', '}}', {
{'200.200.200.200', '0'},
{'200.200.200.0/24', '0'},
{'0.0.0.0', '0'},
{'0.0.0.0/24', '0'},
{'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD', '0'},
{'00AB:0002:3008:8CFD::/64', '1'},
{'0::0/64', '1'},
{'0::0', '0'},
})
end
function p:test_temp_user()
self:preprocess_equals_many('{{#invoke:IPAddress/sandbox|isTempUser|', '}}', {
{'200.200.200.200', '0'},
{'200.200.200.0/24', '0'},
{'0.0.0.0', '0'},
{'0.0.0.0/24', '0'},
{'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD', '0'},
{'00AB:0002:3008:8CFD::/64', '0'},
{'0::0/64', '0'},
{'0::0', '0'},
{'~2025-12345-67', '1'},
{'2025-12345-67', '0'},
{'Example', '0'}
})
end
function p:test_perm_user()
self:preprocess_equals_many('{{#invoke:IPAddress/sandbox|isPermUser|', '}}', {
{'200.200.200.200', '0'},
{'200.200.200.0/24', '0'},
{'0.0.0.0', '0'},
{'0.0.0.0/24', '0'},
{'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD', '0'},
{'00AB:0002:3008:8CFD::/64', '0'},
{'0::0/64', '0'},
{'0::0', '0'},
{'~2025-12345-67', '0'},
{'2025-12345-67', '1'},
{'Example', '1'}
})
end
function p:test_user()
self:preprocess_equals_many('{{#invoke:IPAddress/sandbox|isUser|', '}}', {
{'200.200.200.200', ''},
{'200.200.200.0/24', ''},
{'0.0.0.0', ''},
{'0.0.0.0/24', ''},
{'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD', ''},
{'00AB:0002:3008:8CFD::/64', ''},
{'0::0/64', ''},
{'0::0', ''},
{'~2025-12345-67', 'temp'},
{'2025-12345-67', 'perm'},
{'Example', 'perm'}
})
end
function p:test_main()
self:preprocess_equals_many('{{#invoke:IPAddress/sandbox|main|', '}}', {
{'200.200.200.200', 'ip'},
{'200.200.200.0/24', 'range'},
{'0.0.0.0', 'ip'},
{'0.0.0.0/24', 'range'},
{'00AB:0002:3008:8CFD:00AB:0002:3008:8CFD', 'ip'},
{'00AB:0002:3008:8CFD::/64', 'range'},
{'0::0/64', 'range'},
{'0::0', 'ip'},
{'~2025-12345-67', 'temp'},
{'2025-12345-67', 'perm'},
{'Example', 'perm'}
})
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.