Debian Codegraph @

extensions/Scribunto/tests/phpunit/Engines/LuaCommon/HashLibraryTests.lua

raw symbols SCIP
1 --[[
2 Tests for the mw.hash module
3
4 @license GNU GPL v2+
5 @author Marius Hoch < [email protected] >
6 ]]
7
8 local testframework = require 'Module:TestFramework'
9
10 local function testListAlgorithms()
11 local algos = mw.hash.listAlgorithms()
12
13 if type( algos ) ~= 'table' then
14 return 'algo list was expected to be a table'
15 end
16
17 for i, v in ipairs( algos ) do
18 if v == 'md5' then
19 return true
20 end
21 end
22
23 return 'md5 was expected to be in the algo list'
24 end
25
26 -- Tests
27 local tests = {
28 { name = 'mw.hash.listAlgorithms', func = testListAlgorithms,
29 expect = { true }
30 },
31 { name = 'mw.hash.hashValue sha1', func = mw.hash.hashValue,
32 args = { 'sha1', 'abc' },
33 expect = { 'a9993e364706816aba3e25717850c26c9cd0d89d' }
34 },
35 { name = 'mw.hash.hashValue md5', func = mw.hash.hashValue,
36 args = { 'md5', 'abc' },
37 expect = { '900150983cd24fb0d6963f7d28e17f72' }
38 },
39 { name = 'mw.hash.hashValue bad argument type #1', func = mw.hash.hashValue,
40 args = { nil, 'a-string' },
41 expect = "bad argument #1 to 'hashValue' (string expected, got nil)"
42 },
43 { name = 'mw.hash.hashValue bad argument type #2', func = mw.hash.hashValue,
44 args = { 'abc', 2 },
45 expect = "bad argument #2 to 'hashValue' (string expected, got number)"
46 },
47 { name = 'mw.hash.hashValue bad algorithm', func = mw.hash.hashValue,
48 args = { 'not-a-hashing-algorithm', 'abc' },
49 expect = "Unknown hashing algorithm: not-a-hashing-algorithm"
50 }
51 }
52
53 return testframework.getTestProvider( tests )