-- Example Unit tests for . Click talk page to run tests.requirestrictlocal p = require('Module:UnitTests')
local frame0 = mw.getCurrentFramelocal frame0_getTitle = frame0:getTitlelocal getCurrentFrame_getTitle = mw.getCurrentFrame:getTitlelocal arg = ...
function p._test(frame) return "# " .. frame:getTitle .. "\n" .. "# " .. frame0:getTitle .. "\n" .. "# " .. frame0_getTitle .. "\n" .. "# " .. getCurrentFrame_getTitle .. "\n" .. "# " .. mw.dumpObject(arg) .. "\n" .. ""end
function p._test0(frame) return "# Module:UnitTests/testcases\n" .. "# Module:UnitTests/testcases\n" .. "# Module:UnitTests/testcases\n" .. "# Module:UnitTests/testcases\n" .. "# nil\n" .. ""end
function p.preprocess(frame) --return frame.args[1] return frame:preprocess(frame.args[1])end
function p.p1(frame) return frame:preprocess('')end
function p.p2(frame) return frame:preprocess('')end
function p:test local testcases_expected_result = "" .. "# Module:UnitTests/testcases\n" .. "# Module:UnitTests/testcases\n" .. "# Module:UnitTests/testcases\n" .. "# Module:UnitTests/testcases\n" .. "" self:preprocess_equals('', "\n" .. testcases_expected_result .. "# nil\n" .. "") self:preprocess_equals('', "\n" .. testcases_expected_result .. "# nil\n" .. "",) self:preprocess_equals('', "\n" .. testcases_expected_result .. "# nil\n" .. "",) local testcases_frame_expected_result = "" .. "# Module:UnitTests/testcases/frame\n" .. "# Module:UnitTests/testcases/frame\n" .. "# Module:UnitTests/testcases/frame\n" .. "# Module:UnitTests/testcases/frame\n" .. "" self:preprocess_equals('', "\n" .. testcases_frame_expected_result .. "# nil\n" .. "") self:equals("mw.getCurrentFrame:preprocess('{{#invoke:UnitTests/testcases/frame | _test}}')", mw.getCurrentFrame:preprocess(''), "\n" .. testcases_frame_expected_result .. "# nil\n" .. "") self:equals("frame0:preprocess('{{#invoke:UnitTests/testcases/frame | _test}}')", frame0:preprocess(''), "\n" .. testcases_frame_expected_result .. "# nil\n" .. "") -- self:equals("require('Module:UnitTests/testcases/frame')._test(mw.getCurrentFrame)", "\n"..require('Module:UnitTests/testcases/frame')._test(mw.getCurrentFrame), "\n" .. testcases_expected_result .. '# "Module:UnitTests/testcases/frame"\n' .. "") self:equals("p._test(frame0)", "\n"..p._test(frame0), "\n" .. testcases_expected_result .. "# nil\n" .. "") self:equals("p._test(mw.getCurrentFrame)", "\n"..p._test(mw.getCurrentFrame), "\n" .. testcases_expected_result .. "# nil\n" .. "") --_test0}}', "\n" .. testcases_expected_result .. "# nil\n" .. "") self:preprocess_equals('', "\n" .. p._test0) self:equals("Blatant fail", "
String 1", "String 2")end--[=[ function p:error1 error("p:error1") end function p.error2 error("p.error2") end function p:error3 error("p:error3") end function p.error3 error("p.error3") end function p.error4 error("p.error4") end function p:error4 error("p:error4") end function p:test_error5 error("p:test_error5") end function p:_test6 error("p:_test6") end function p.ttest_error7 error("p.test_error7") end function p._test8 error("p.test8") end --]=]
return p