Module:Build bracket/testcases
Appearance
| This is the test cases page for the module Module:Build bracket. Results of the test cases. |
require[[strict]]
local Unit = require('Module:UnitTests')
-- CHANGE THIS if you want to point at the non-sandbox module
local MOD = 'Module:Build bracket/sandbox'
local M = require(MOD)
-- Minimal frame that your module expects
local function makeFrame(fargs, pargs)
local parent = mw.getCurrentFrame():newChild{args = pargs}
return parent:newChild{args=fargs}
end
local function render(fargs, pargs)
-- Use the exported _main so we bypass #invoke and still exercise end-to-end
return M._main(makeFrame(fargs, pargs))
end
-------------------------
-- Test cases
-------------------------
function Unit:test_basic_numbered_one_round()
local out = render({
rounds = 1,
['col1-matches'] = '1',
paramstyle = 'numbered',
-- numbered args (teams then scores, per team):
[1] = 'Alpha', [2] = '3',
[3] = 'Beta', [4] = '1',
})
self:heading(out)
self:equals('renders team Alpha', out:find('Alpha') ~= nil, true)
self:equals('renders team Beta', out:find('Beta') ~= nil, true)
end
function Unit:test_numbered_with_seeds()
local out = render({
rounds = 1,
['col1-matches'] = '1',
paramstyle = 'numbered',
seeds = 'yes', -- forceseeds
-- numbered args with seeds first for each team:
[1] = 'A1', [2] = 'Alpha', [3] = '5',
[4] = 'B2', [5] = 'Beta', [6] = '3',
})
self:heading(out)
self:equals('shows seed A1', out:find('>A1<') ~= nil, true)
self:equals('shows seed B2', out:find('>B2<') ~= nil, true)
end
function Unit:test_groups_from_paths()
local out = render({
rounds = 2,
['col1-matches'] = '3,7',
['col2-matches'] = '5',
['col1-col2-paths'] = '(3,7)-5', -- groups should derive at col1 row-pair
['RD1-group1'] = 'Group 1',
--paramstyle = 'numbered',
-- teams across both rounds (col1 has 2 matches = 4 teams; col2 has 1 match = 2 teams)
['RD1-team1'] = 'A', ['RD1-score1'] = '1',
['RD1-team2'] = 'B', ['RD1-score2'] = '2',
['RD1-team3'] = 'C', ['RD1-score3'] = '3',
['RD1-team4'] = 'D', ['RD1-score4'] = '4',
['RD1-team5'] = 'E', ['RD1-score5'] = '5',
['RD2-team1'] = 'F', ['RD2-score1'] = '6',
})
self:heading(out)
self:equals('group label text appears', out:find('>Group 1<') ~= nil, true)
-- group cells render as centered text (class brk-center on the <td>)
self:equals('group cell has center class', out:find('class="[^"]*brk%-center[^"]*"') ~= nil, true)
end
function Unit:test_paths_draw_borders()
local out = render({
rounds = 2,
['col1-matches'] = '1,2',
['col2-matches'] = '1',
['col1-col2-paths'] = '1-1,2-1',
paramstyle = 'numbered',
[1]='T1',[2]='1',[3]='T2',[4]='2',[5]='T3',[6]='3',[7]='T4',[8]='4',[9]='T5',[10]='5',[11]='T6',[12]='6',
})
-- Path <td>s use inline border-width to draw lines; just sanity check it exists
self:heading(out)
self:equals('path cells rendered (inline border-width present)',
out:find('border%-width:%s*%d+px') ~= nil, true)
end
function Unit:test_cross_background()
local out = render({
rounds = 2,
['col1-matches'] = '1,5',
['col2-matches'] = '1,5',
['col1-col2-paths'] = '1-5,5-1',
['col1-col2-cross'] = '3',
paramstyle = 'numbered',
'AA','1','BB','2', '','CC','3','DD','4','EE','5','FF','6', '','GG','7','HH','8','II','9','KK','10',
})
self:heading(out)
-- Cross cells use linear-gradient backgrounds; just check presence
self:equals('cross background drawn', out:find('linear%-gradient%(') ~= nil, true)
end
-- (Optional) autocol spacing sanity (does not assert layout, only no crash)
function Unit:test_autocol_ok()
local out = render({
rounds = 2,
autocol = 'y',
['col1-matches'] = '1',
['col1-col2-paths'] = '1-1',
['col2-matches'] = '1',
paramstyle = 'numbered',
[1]='X',[2]='1',[3]='Y',[4]='2',[5]='Z',[6]='3',[7]='W',[8]='4',
})
self:heading(out)
self:equals('no empty result, rendered some HTML', type(out) == 'string' and #out > 0, true)
end
return Unit