Module:Sandbox/Aidan9382: Difference between revisions

Content deleted Content added
test
that's cool
 
(24 intermediate revisions by the same user not shown)
Line 1:
if mw.title.getCurrentTitle().prefixedText == "Module:Sandbox/Aidan9382" then
require('Module:Module wikitext')._addText('{{User:Aidan9382/sandbox/header|nolint=y}}')
require('Module:Module wikitext')._addText('{{User:Aidan9382/sandbox/header|nolint=y}}')
end
require("strict")
local p = {}
Line 7 ⟶ 9:
end
 
function p.Debug(arg1, arg2) -- General-purpose debugger/testing tool; combines multiple submodules
function p.iloveregexold()
-- Runs CodeAnalysis and Benchmarker
local r = "%[?%[?.-:([^{|]+)%]?%]?"
-- Benchmarker expects either p and the module name or the return function and the module name
local args = {mw.ustring.match("[[File:Hey.jpg|thumb|left|250px]]",r)}
-- This is to be required in the module, not `#invoke:`ed
return table.concat(args," -- ")
require('Module:Module wikitext')._addText('{{#invoke:Sandbox/Aidan9382/CodeAnalysis|main}}')
end
local Hook = require("Module:Sandbox/Aidan9382/Benchmarker")
function p.iloveregex()
local t = type(arg1) == "table" and arg1 or type(arg1) == "nil" and {} or nil
--This assumes [[ is present, and that therefore ]] is present
if t then
local r = "%[%[%a-:([^{|]+)(.+)%]%]"
return Hook(t, arg2 or "root module")
local args = {mw.ustring.match("[[File:Hey.jpg|thumb|left|250px|All for [[Module:Excerpt/portals]]|alt=text]]",r)}
elseif type(arg1) == "function" then
return table.concat(args," -- ")
return Hook(arg1, arg2 or "root module")
end
elseif arg1 ~= false then
 
mw.log("Aidan9382 | Unable to load Benchmarker (unexpected arg setup)")
function p.parentingLogic(frame)
--Note: Not even sure this thing goes beyond 1 parent, but have overcomplicated code anyways
local parentChain = {}
local newframe = frame
while true do
local parent = newframe:getParent()
if not parent then
break
end
newframe = parent
parentChain[#parentChain+1] = parent
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 ⟶ 70:
 
return childFrame
end
 
--[[ Note
Scribunto really doesn't want or like you doing things like what this function
aims to do (basically "hook" _G), and the outputs are completely not what you
would expect from the below code. Unsure how much of this is exactly "intended"
--]]
local GE_logs = {}
local GE_messages = {}
function p.globalExperiments()
if rawget(_G, "_ranGE") then
return
end
rawset(_G, "_ranGE", true)
local _tostring = tostring
local _type = type
local _next = next
local _pairs = pairs
local _rawset = rawset
local scanned = {}
local _sort = table.sort
local function notelog(message)
if GE_logs[message] then
GE_logs[message] = GE_logs[message] + 1
else
GE_logs[message] = 1
GE_messages[#GE_messages+1] = message
end
end
local function recursive(t, path)
scanned[t] = true
for a,b in _next,t do
--for a,b in _pairs(t) do
if _type(b) == "table" and not scanned[b] then
recursive(b, path .. _tostring(a) .. ".")
elseif _type(b) == "function" then
_rawset(t, a, function(...)
notelog("(GHook) Just accessed " .. path .. _tostring(a))
return b(...)
end)
--notelog("(GHook) Hooked " .. path .. _tostring(a))
end
end
end
recursive(_G, "")
end
function p.dumpGELogs()
table.sort(GE_messages, function(x,y) return GE_logs[x]>GE_logs[y] end)
for _,message in next,GE_messages do
mw.log("(x" .. GE_logs[message] .. ") " .. message)
end
end
 
Line 160 ⟶ 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 181 ⟶ 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
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 outs = {}
local start = os.clock()
for i = 1, tonumber(frame.args[2]) or 10 do
outs[#outs+1] = frame:preprocess(text)
end
local duration = os.clock() - start
return "Time taken: " .. duration .. "\n\n" .. table.concat(outs, frame.args[3] or "\n")
end
 
Line 193 ⟶ 115:
local x = 5
until x == 5
end
 
function p.WasteExecutionTime(frame)
local t = tonumber(frame.args[1]) or 0
local start = os.clock()
while os.clock()-start < t do end
return "Wasted " .. (os.clock()-start) .. " seconds"
end
 
p["+expensive"] = function()
mw.incrementExpensiveFunctionCount()
return ""
end