Módulo:URL/tests
La documentación para este módulo puede ser creada en Módulo:URL/tests/doc
mw.loader.load( '//en.wikipedia.org/wiki/Module:Urltowiki?action=raw&ctype=text/javascript' );
---- Tests para el [[Módulo:URL]]. El resultado está en la página de discusión.
local z = {}
function z.enlazar(url, texto)
--if true then return 'url: ' .. (url or '') .. ' texto: ' .. (texto or '') end
if not url or
url:match('^%s*$') then
return
elseif url:find('%[') or
url:match('^{{{.*}}}$') then -- Por ejemplo, un parámetro de una plantilla, {{{página web|}}}
return url
elseif z.esValida(url) then
urlCorregida = url
else
urlCorregida = 'http://' .. url
end
if texto then
return '[' .. urlCorregida .. ' ' .. texto .. ']'
else
textoCorregido = urlCorregida:match('^http://(.+)') or
urlCorregida:match('^https://(.+)') or
urlCorregida
-- Eliminar la / al final
textoCorregido = textoCorregido:match('(.+)/$') or textoCorregido
return '[' .. urlCorregida .. ' ' .. textoCorregido .. ']'
end
end
function z.url(frame)
if not frame or not frame.args then
return
end
return z.enlazar(frame.args[1], frame.args[2])
end
--function z.enlacePlano
-- Ver la plantilla Enlace plano
-- return
--end
-- Ver la función checkurl del módulo de citas.
function z.esValida(url)
return url:sub(1,2) == "//" or url:match( "^[^/]*:" )
end
local z = {}
function z.decodificar(frame)
local enctype = frame.args[2]
local ret = nil;
if (frame.args[2] ~= nil) then
enctype = mw.ustring.upper(enctype)
if ((enctype == "QUERY") or (enctype == "PATH") or (enctype == "WIKI")) then
ret = mw.uri.decode(frame.args[1],frame.args[2])
end
else
ret = mw.uri.decode(frame.args[1])
end
ret = string.gsub(ret, "{", "{")
ret = string.gsub(ret, "}", "}")
return ret
end
function z.decode( frame )
local new_args = str._getParameters( frame.args, {'url'} );
local url = new_args['url'] or '';
return mw.uri.decode( url )
end
return z