Module:Sandbox/Aidan9382: Difference between revisions

Content deleted Content added
+ some testing
that's cool
 
(8 intermediate revisions by the same user not shown)
Line 9:
end
 
function p.Debug(arg1, arg2) -- General-purpose debugger/testing tool; combines multiple submodules
function p.parentingLogic(frame)
-- Runs CodeAnalysis and Benchmarker
--Note: Not even sure this thing goes beyond 1 parent, but have overcomplicated code anyways
-- Benchmarker expects either p and the module name or the return function and the module name
local parentChain = {}
-- This is to be required in the module, not `#invoke:`ed
local newframe = frame
require('Module:Module wikitext')._addText('{{#invoke:Sandbox/Aidan9382/CodeAnalysis|main}}')
while true do
local Hook = require("Module:Sandbox/Aidan9382/Benchmarker")
local parent = newframe:getParent()
local t = type(arg1) == "table" and arg1 or type(arg1) == "nil" and {} or nil
if not parent then
if t then
break
return Hook(t, arg2 or "root module")
end
elseif type(arg1) == "function" then
newframe = parent
return Hook(arg1, arg2 or "root module")
parentChain[#parentChain+1] = parent
elseif arg1 ~= false then
mw.log("Aidan9382 | Unable to load Benchmarker (unexpected arg setup)")
end
local parentText = ""
for i,p in next,parentChain do
parentText = parentText .. " parent"..i.."="..p:getTitle()
end
return "frame="..frame:getTitle()..parentText.." mw.gct="..mw.title.getCurrentTitle().text
end
 
p["module-use"] = function(frame)
local parentLogicStuff = p.parentingLogic(frame)
local testlogic = "\n\n"
local i = 1
while true do
local c = frame.args["_test"..i]
if c then
testlogic = testlogic .. "_test"..i.."="..c
else
break
end
i = i + 1
end
return parentLogicStuff..testlogic
end
 
Line 99 ⟶ 80:
else
return "{{DEFAULTSORT:XYZ}}"
end
end
 
function p.magicWordTests2(frame)
local args = frame.args
if args.process == "y" then
frame:preprocess("{{#assessment:Testing|B|Low}}")
elseif args.returnprocess == "y" then
return frame:preprocess("{{#assessment:Testing|B|Low}}")
else
return "{{#assessment:Testing|B|Low}}"
end
end
Line 120 ⟶ 90:
function p.SpeedTest(frame)
local text = mw.text.unstripNoWiki(frame.args[1])
local outouts = ""{}
local start = os.clock()
for i = 1, tonumber(frame.args[2]) or 10 do
local r = tostring(math.random())
outouts[#outs+1] = out .. string.sub(frame:preprocess(text..r),1,-(1+#r)) .. (frame.args[3] or "\n")
end
local duration = os.clock() - start
return out
return "Time taken: " .. duration .. "\n\n" .. table.concat(outs, frame.args[3] or "\n")
end
 
function p.SpeedTestNoRandom(frame)
local text = mw.text.unstripNoWiki(frame.args[1])
local outouts = ""{}
local start = os.clock()
for i = 1, tonumber(frame.args[2]) or 10 do
outouts[#outs+1] = out .. frame:preprocess(text) .. (frame.args[3] or "\n")
end
local duration = os.clock() - start
return out
return "Time taken: " .. duration .. "\n\n" .. table.concat(outs, frame.args[3] or "\n")
end
 
Line 148 ⟶ 122:
while os.clock()-start < t do end
return "Wasted " .. (os.clock()-start) .. " seconds"
end
 
function p.Debug(arg1, arg2) -- General-purpose debugger/testing tool; combines multiple submodules
-- Runs CodeAnalysis and Benchmarker
-- Benchmarker expects either p and the module name or the return function and the module name
-- This is to be required in the module, not `#invoke:`ed
require('Module:Module wikitext')._addText('{{#invoke:Sandbox/Aidan9382/CodeAnalysis|main}}')
local Hook = require("Module:Sandbox/Aidan9382/Benchmarker")
local t = type(arg1) == "table" and arg1 or type(arg1) == "nil" and {} or nil
if t then
return Hook(t, arg2 or "root module")
elseif type(arg1) == "function" then
return Hook(arg1, arg2 or "root module")
elseif arg1 ~= false then
mw.log("Aidan9382 | Unable to load Benchmarker (unexpected arg setup)")
end
end