Module:Current events monthly archive/testcases explained

-- Unit tests for .-- View to run tests.-- While editing, preview this against

-- We are just going to test the date info, and assume that all our argument--- checking code is correct, so make that clear here.local getDateInfo = require('Module:Current events monthly archive/sandbox').getDateInfolocal suite = require('Module:ScribuntoUnit'):new

-- Test datalocal testData =

for _, dateData in ipairs(testData) do local year = dateData.date.year local month = dateData.date.month for field, value in pairs(dateData.results) do local funcName = string.format('test_%04d_%02d_%s', year, month, field ) suite[funcName] = function (self) -- We could have got the date info once for each date, -- but doing it once for each field ensures that our -- tests don't depend on any state changes made by -- previous tests. This makes the tests less efficient, -- but probably not enough to make much actual -- difference. local dateInfo = getDateInfo(year, month) self:assertEquals(value, dateInfo[field]) end endend

function suite:test_current_date local year = tonumber(os.date('%Y')) local month = tonumber(os.date('%m')) local dateInfo = getDateInfo(year, month) self:assertEquals(year, dateInfo.year) self:assertEquals(month, dateInfo.monthNumber) self:assertEquals('is', dateInfo.beVerb)end

function suite:test_next_month local year = tonumber(os.date('%Y')) local month = tonumber(os.date('%m')) + 1 if month

13 then month = 1 year = year + 1 end local dateInfo = getDateInfo(year, month) self:assertEquals(year, dateInfo.year) self:assertEquals(month, dateInfo.monthNumber) self:assertEquals('is', dateInfo.beVerb)end

function suite:test_last_month local year = tonumber(os.date('%Y')) local month = tonumber(os.date('%m')) - 1 if month

0 then month = 12 year = year - 1 end local dateInfo = getDateInfo(year, month) self:assertEquals(year, dateInfo.year) self:assertEquals(month, dateInfo.monthNumber) self:assertEquals('was', dateInfo.beVerb)end

function suite:test_december_this_year local year = tonumber(os.date('%Y')) local month = 12 local dateInfo = getDateInfo(year, month) self:assertEquals(year, dateInfo.year) self:assertEquals(month, dateInfo.monthNumber) self:assertEquals('is', dateInfo.beVerb)end

function suite:test_january_next_year local year = tonumber(os.date('%Y')) + 1 local month = 1 local dateInfo = getDateInfo(year, month) self:assertEquals(year, dateInfo.year) self:assertEquals(month, dateInfo.monthNumber) self:assertEquals('is', dateInfo.beVerb)end

return suite