Mô đun:UnitTests/testcases

-- Example Unit tests for Mô đun:UnitTests. Click talk page to run tests.
requirestrict
local p = require('Mô đun:UnitTests')

local frame0 = mw.getCurrentFrame()
local frame0_getTitle = frame0:getTitle()
local getCurrentFrame_getTitle = mw.getCurrentFrame():getTitle()
local 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
" Mô đun:UnitTests/testcases\n" ..
" Mô đun:UnitTests/testcases\n" ..
" Mô đun:UnitTests/testcases\n" ..
" Mô đun: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 = "" ..
" Mô đun:UnitTests/testcases\n" ..
" Mô đun:UnitTests/testcases\n" ..
" Mô đun:UnitTests/testcases\n" ..
" Mô đun:UnitTests/testcases\n" ..
""
self:preprocess_equals(, "\n" ..
testcases_expected_result ..
" nil\n" ..
"")
self:preprocess_equals(, "\n" ..
testcases_expected_result ..
" nil\n" ..
"", {nowiki=true})
self:preprocess_equals(, "\n" ..
testcases_expected_result ..
" nil\n" ..
"", {combined=true})
local testcases_frame_expected_result = "" ..
" Mô đun:UnitTests/testcases/frame\n" ..
" Mô đun:UnitTests/testcases/frame\n" ..
" Mô đun:UnitTests/testcases/frame\n" ..
" Mô đun:UnitTests/testcases/frame\n" ..
""
self:preprocess_equals(, "\n" ..
testcases_frame_expected_result ..
" nil\n" ..
"")
self:equals("mw.getCurrentFrame():preprocess( )",
mw.getCurrentFrame():preprocess( ),
"\n" ..
testcases_frame_expected_result ..
" nil\n" ..
"")
self:equals("frame0:preprocess( )",
frame0:preprocess( ),
"\n" ..
testcases_frame_expected_result ..
" nil\n" ..
"")
--self:equals("frame0:expandTemplate{ title = 'invoke:UnitTests/testcases/frame', args = { '_test' } }",
frame0:expandTemplate{ title = 'invoke:UnitTests/testcases/frame', args = { '_test' } },
"\n" ..
testcases_frame_expected_result ..
" nil\n" ..
"")
self:equals("require('Mô đun:UnitTests/testcases/frame')._test(mw.getCurrentFrame())",
"\n"..require('Mô đun:UnitTests/testcases/frame')._test(mw.getCurrentFrame()),
"\n" ..
testcases_expected_result ..
' "Mô đun: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" ..
"")
--self:preprocess_equals(, "\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