local p = {}
local live = require('Module:Road data')
local sandbox = require('Module:Road data/sandbox')
local p = {}
local function showArgs(args)
local out = ''
for _, arg in ipairs(args) do
out = out .. mw.getCurrentFrame():preprocess('<syntaxhighlight lang="lua">' .. mw.dumpObject(arg) .. '</syntaxhighlight>')
end
return out
end
local function addTest(out, functionName, ...)
out = out .. '|-\n'
out = out .. '| <code>' .. functionName .. '</code> with parameters:' .. showArgs(arg) .. '\n'
-- out = out .. '| ' .. live[functionName](unpack(arg)) .. '\n'
out = out .. '| ' .. sandbox[functionName](unpack(arg)) .. '\n'
return out
end
local function startTable(out)
out = out .. '{| class="wikitable"\n'
out = out .. '! Lua' .. '\n'
-- out = out .. '! Live'
out = out .. '! Sandbox' .. '\n'
return out
end
local function endTable(out)
out = out .. '|}\n'
return out
end
local NIL = setmetatable({}, { __tostring = function() return 'nil' end })
function p.test(frame)
local out = ''
out = out .. '== <code>shield</code> ==\n'
out = startTable(out)
out = addTest(out, 'shield', { country = 'USA', state = 'ny', type = 'I', route = '10' })
out = addTest(out, 'shield', { country = 'ITA', type = 'RA', route = '5' }, NIL, 'jct')
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Hwy', route = '5' }, NIL, 'jct')
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Hwy', route = '5' }, 'normal (or anything)', 'jct')
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Hwy', route = '5' }, 'list', 'jct')
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Hwy', route = '5' }, 'main', 'jct')
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Hwy', route = '5', to = true }, NIL, 'jct')
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Hwy', route = '5', to = true }, 'main', 'jct')
out = addTest(out, 'shield', { country = 'USA', state = 'FL', type = 'Both', route = '821' }, NIL, 'jct')
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Hwy', route = '5' }, 'main', 'infobox', true)
out = addTest(out, 'shield', { country = 'USA', state = 'FL', type = 'Both', route = '821'}, 'main', 'infobox', true)
out = addTest(out, 'shield', { country = 'USA', state = 'FL', type = 'Both', route = '821', to = true})
out = addTest(out, 'shield', { country = 'USA', type = 'I', route = '12', dir = 'north'})
out = addTest(out, 'shield', { country = 'USA', type = 'I', route = '12', to = true, dir = 'north'})
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Hwy', route = '9999'})
out = addTest(out, 'shield', { country = 'USA', type = 'I', route = '90', to = true }, NIL, '120px')
out = addTest(out, 'shield', { country = 'CAN', province = 'ON', type = 'Toll', route = '407' }, 'main', 'rdt')
out = endTable(out)
out = out .. '== <code>link</code> ==\n'
out = startTable(out)
out = addTest(out, 'link', { type = 'I', route = '90', state = 'NY' })
out = addTest(out, 'link', { type = 'I', route = '90', state = 'NY' }, true)
out = addTest(out, 'link', { type = 'I', route = '10', state = 'NY' })
out = addTest(out, 'link', { type = 'RA', route = '5', country = 'ITA' })
out = addTest(out, 'link', { type = 'RA', route = '5', country = 'ITA' }, true)
out = addTest(out, 'link', { type = 'Hwy', route = '5', province = 'ON' })
out = endTable(out)
return out
end
return p