Editing Module:Sandbox/Vergir

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
-- TEMPORARY diagnostic.
-- Renders heroes through the LIVE Module:InfoboxHero twice each and compares the
-- two outputs, to establish whether rendering is deterministic at all.
-- {{#invoke:Sandbox/Vergir|selfdiff}}
local p = {}
local p = {}
local infobox = require('Module:InfoboxHero')
local SAMPLE_HEROES = {
'hero_atlas',
'hero_viscous',
'hero_haze',
'hero_werewolf',
'hero_targetdummy',
}
-- Byte offset of the first difference, or nil when the strings are equal.
local function first_diff(a, b)
local limit = math.min(#a, #b)
for i = 1, limit do
if a:sub(i, i) ~= b:sub(i, i) then return i end
end
if #a ~= #b then return limit + 1 end
return nil
end
function p.selfdiff(frame)
local keys = {}
if frame.args[1] and frame.args[1] ~= '' then
for key in string.gmatch(frame.args[1], '[^,%s]+') do
table.insert(keys, key)
end
else
keys = SAMPLE_HEROES
end
local out = {}
local mismatches = 0
for _, hero_key in ipairs(keys) do
local child = frame:newChild{ args = { key = hero_key } }
local a = tostring(infobox.render(child))
local b = tostring(infobox.render(child))
local at = first_diff(a, b)
if at ~= nil then
mismatches = mismatches + 1
local from = math.max(1, at - 50)
local to = at + 50
table.insert(out, '* <code>' .. hero_key .. '</code> differs at byte ' .. at ..
' (len ' .. #a .. ' vs ' .. #b .. ')')
table.insert(out, '** A: <code>' .. mw.text.nowiki(a:sub(from, to)) .. '</code>')
table.insert(out, '** B: <code>' .. mw.text.nowiki(b:sub(from, to)) .. '</code>')
end
end
return 'Same module rendered twice per hero, heroes: ' .. #keys ..
'\n\nNon-deterministic: ' .. mismatches .. '\n' .. table.concat(out, '\n')
end
return p
return p
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: