Jump to content

Module:URL/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dcoetzee (talk | contribs) at 22:59, 26 February 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:URL]]. Click talk page to run tests.
local p = require('Module:UnitTests')
 
function p:test_url()
    self:preprocess_equals_many('{{#invoke:URL|url|', '}}', {
        {'', self.frame:preprocess("{{tlx|URL|''example.com''|''optional display text''}}")},
        {' EXAMPLE.com ', '[http://example.com/ example.com]'},
        {' example.com ', '[http://example.com/ example.com]'},
        {' www.example.com ', '[http://www.example.com/ www.example.com]'},
        {' http://www.example.com ', '[http://www.example.com/ www.example.com]'},
        {' https://www.example.com ', '[https://www.example.com/ www.example.com]'},
        {' ftp://www.example.com ', '[ftp://www.example.com/ www.example.com]'},
        {' ftp://ftp.example.com ', '[ftp://ftp.example.com ftp.example.com]'},
        {' http://www.example.com/ ', '[http://www.example.com/ www.example.com]'},
        {' http://www.example.com/path ', '[http://www.example.com/path www.example.com/path]'},
        {' www.example.com/foo ', '[http://www.example.com/foo www.example.com/foo]'},
        {' http://www.example.com/foo | link ', '[http://www.example.com/foo link]'},
        {' www.example.com/foo | link ', '[http://www.example.com/foo link]'},
        {' http://www.example.com/path/ ', '[http://www.example.com/path/ www.example.com/path/]'},
        {' www.example.com/foo/ ', '[http://www.example.com/foo/ www.example.com/foo/]'},
        {' 1=http://www.example.com/path?section=17 ', '[http://www.example.com/path?section=17 www.example.com/path?section=17]'},
        {' 1=www.example.com/foo?page=42 ', '[http://www.example.com/foo?page=42 www.example.com/foo?page=42]'},
        {' http://www.example.com/foo/ | link ', '[http://www.example.com/foo/ link]'},
        {' www.example.com/foo/ | link ', '[http://www.example.com/foo/ link'},
    })
end

return p