local hash = require('Module:Hash')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
function suite:test_MD5()
-- Empty message
self:assertEquals(
'd41d8cd98f00b204e9800998ecf8427e',
hash.MD5().hexdigest()
)
-- Simple string
self:assertEquals(
'd464064618e61b35dca3e5dee84c7b56',
hash.MD5('My hovercraft is full of eels.').hexdigest()
)
-- String with wiki markup
self:assertEquals(
'b3d7a3def78ea051ceae75944d18e9ae',
hash.MD5("I ''will'' not buy this record; it is scratched.").hexdigest()
)
-- String with UTF-8 code points > U+007F
self:assertEquals(
'a2f692444dc26e1ca4a7e1bde7454516',
hash.MD5('A mellbimbóim örömmel robbant fel!').hexdigest()
)
-- String spanning multiple blocks
self:assertEquals(
'95240753871efe4438583851bec99f76',
hash.MD5("According to all known laws of aviation, there is no way that a bee should be able to fly. Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyways. Because bees don't care what humans think is impossible.").hexdigest()
)
-- Fluent interface
local bee_movie_script = hash.MD5('According to all known laws of aviation, there is no way that a bee should be able to fly. ')
self:assertEquals(bee_movie_script, bee_movie_script.update('Its wings are too small to get its fat little body off the ground. '))
self:assertEquals(bee_movie_script, bee_movie_script.update('The bee, of course, flies anyways. ')
.update("Because bees don't care what humans think is impossible."))
self:assertEquals('95240753871efe4438583851bec99f76', bee_movie_script.hexdigest())
self:assertThrows(
function() return bee_movie_script.update("Yellow, black. Yellow, black. Yellow, black. Yellow, black. Yellow, black. Yellow, black. Ooh, black and yellow! Yeah, let's shake it up a little!") end,
'MD5 context has already been finalized'
)
end
function suite:test_md5_hexdigest()
-- No args
self:assertThrows(
function() return hash.md5_hexdigest({args = {}}) end,
'Function must be invoked with at least one anonymous or numbered parameter'
)
-- No valid args
self:assertThrows(
function() return hash.md5_hexdigest({args = {[99] = "This is out of `ipairs`' reach"}}) end,
'Function must be invoked with at least one anonymous or numbered parameter'
)
-- Empty first arg
self:assertResultEquals(
'd41d8cd98f00b204e9800998ecf8427e',
'{{#invoke:Hash|md5_hexdigest|}}'
)
-- Simple string
self:assertResultEquals(
'd464064618e61b35dca3e5dee84c7b56',
'{{#invoke:Hash|md5_hexdigest|My hovercraft is full of eels.}}'
)
-- String with wiki markup
self:assertResultEquals(
'b3d7a3def78ea051ceae75944d18e9ae',
"{{#invoke:Hash|md5_hexdigest|I ''will'' not buy this record; it is scratched.}}"
)
-- String with UTF-8 code points > U+007F
self:assertResultEquals(
'a2f692444dc26e1ca4a7e1bde7454516',
'{{#invoke:Hash|md5_hexdigest|A mellbimbóim örömmel robbant fel!}}'
)
-- String spanning multiple blocks
self:assertResultEquals(
'95240753871efe4438583851bec99f76',
"{{#invoke:Hash|md5_hexdigest|According to all known laws of aviation, there is no way that a bee should be able to fly. Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyways. Because bees don't care what humans think is impossible.}}"
)
-- Anonymous and numbered args
self:assertResultEquals(
'921dd5cd804ebb55e773bb5d6df63bd9',
'{{#invoke:Hash|md5_hexdigest|manga|2=vol=69|3=ch=420|4=pp=1-3,37}}'
)
-- Out-of-order anonymous and numbered args
self:assertResultEquals(
'921dd5cd804ebb55e773bb5d6df63bd9',
'{{#invoke:Hash|md5_hexdigest|4=pp=1-3,37|3=ch=420|2=vol=69|manga}}'
)
-- Out-of-order anonymous and numbered args, with overriding and non-sequential numbered args ignored
self:assertResultEquals(
'3c81892062835fc5c8ce15fddee1a507',
"{{#invoke:Hash|md5_hexdigest|first|overridden second|3=overridden third|third|2=second|fourth|99=This is out of `ipairs`' reach}}"
)
-- Whitespace preservation on anonymous args
self:assertResultEquals(
'651a6b1f73d8f7013c398b9a4505f295',
'{{#invoke:Hash|md5_hexdigest| My hovercraft is full of eels. }}'
)
-- Whitespace stripping on numbered args
self:assertResultEquals(
'd464064618e61b35dca3e5dee84c7b56',
'{{#invoke:Hash|md5_hexdigest|1= My hovercraft is full of eels. }}'
)
end
return suite
Advertisement
Advertisement