Module:Broken links/testcases

-- Unit tests for Module:Broken links. Click talk page to run tests. -- Example usage: --  -- Console example: --  mw.log(p.run_tests(mw.getCurrentFrame))

require('strict')

local p = require('Module:UnitTests')

local _invoke = "" local _banner = "\n" .. ": Generator: github.com/bogle-tools/site/tree/main/tools/WikiLinks\n" .. ": Timestamp: 2023-10-12T09:39:49.9303979-07:00\n" local _nowiki = {nowiki = true} local _expect = function(s) return _banner .. s:gsub("^%s*", ""):gsub("\n%s*", "\n") end

function p:test_summary self:preprocess_equals(_invoke:gsub(" ", "summary=yes"), _expect([=[ : Total 2 articles, 3 broken links ]=])) end

function p:test_full_output self:preprocess_equals(_invoke:gsub(" ", ""), _expect([=[ : Total 2 articles, 3 broken links * 401(k) ** http://www.ebri.org/pdf/publications/facts/0205fact.a.pdf (ERROR,Not Found) * Campbell R. Harvey ** http://academic.research.microsoft.com/Author/1867124/campbell-r-harvey (ERROR,No such host is known. (academic.research.microsoft.com:80)) ** http://www.cfapubs.org/doi/abs/10.2469/faj.v62.n2.4084 (OTHER,Forbidden) ]=]), _nowiki) end

function p:test_pattern_matching self:preprocess_equals(_invoke:gsub(" ", "pattern=^ERROR"), _expect([=[ : Total 2 articles, 2 broken links, filtered by '^ERROR' * 401(k) ** http://www.ebri.org/pdf/publications/facts/0205fact.a.pdf (ERROR,Not Found) * Campbell R. Harvey ** http://academic.research.microsoft.com/Author/1867124/campbell-r-harvey (ERROR,No such host is known. (academic.research.microsoft.com:80)) ]=]), _nowiki) self:preprocess_equals(_invoke:gsub(" ", "pattern=^OTHER"), _expect([=[ : Total 2 articles, 1 broken link, filtered by '^OTHER' * Campbell R. Harvey ** http://www.cfapubs.org/doi/abs/10.2469/faj.v62.n2.4084 (OTHER,Forbidden) ]=]), _nowiki) self:preprocess_equals(_invoke:gsub(" ", "pattern=^NOT_PRESENT"), _expect([=[ : Total 2 articles, 0 broken links, filtered by '^NOT_PRESENT' ]=]), _nowiki) end

function p:test_page_selection self:preprocess_equals(_invoke:gsub(" ", "page=401(k)"), _expect([=[ : Total 2 articles, 1 broken link, page '401(k)' * 401(k) ** http://www.ebri.org/pdf/publications/facts/0205fact.a.pdf (ERROR,Not Found) ]=]), _nowiki) self:preprocess_equals(_invoke:gsub(" ", "page=Campbell R. Harvey"), _expect([=[ : Total 2 articles, 2 broken links, page 'Campbell R. Harvey' * Campbell R. Harvey ** http://academic.research.microsoft.com/Author/1867124/campbell-r-harvey (ERROR,No such host is known. (academic.research.microsoft.com:80)) ** http://www.cfapubs.org/doi/abs/10.2469/faj.v62.n2.4084 (OTHER,Forbidden) ]=]), _nowiki) self:preprocess_equals(_invoke:gsub(" ", "page=NOT_PRESENT"), _expect([=[ : Total 2 articles, 0 broken links, page 'NOT_PRESENT' (no data) ]=]), _nowiki) end

function p:test_combinations self:preprocess_equals(_invoke:gsub(" ", "pattern=^ERROR|page=Campbell R. Harvey"), _expect([=[ : Total 2 articles, 1 broken link, page 'Campbell R. Harvey', filtered by '^ERROR' * Campbell R. Harvey ** http://academic.research.microsoft.com/Author/1867124/campbell-r-harvey (ERROR,No such host is known. (academic.research.microsoft.com:80)) ]=]), _nowiki) self:preprocess_equals(_invoke:gsub(" ", "pattern=^ERROR|page=Campbell R. Harvey|summary=yes"), _expect([=[ : Total 2 articles, 1 broken link, page 'Campbell R. Harvey', filtered by '^ERROR' ]=]), _nowiki) end

return p