Module:URL/testcases

-- Unit tests for Module:URL. Click talk page to run tests. local p = require('Module:UnitTests') function p:test_url local cases = { ,       ,        ,    }    text = self.frame:expandTemplate{ title = 'tlx', args = { 'URL', "example.com", "optional display text''" } } for _, case in ipairs(cases) do       self:preprocess_equals(case, text) end cases = { {'http://www.example.com/foo/bar?a=b&#x26;c=d', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar?a=b&#x26;c=d'}, {'EXAMPLE.com', 'example&#x3c;wbr/&#x3e;.com'}, {'example.com', 'example&#x3c;wbr/&#x3e;.com'}, {'www.example.com', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'http://www.example.com', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'https://www.example.com', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'ftp://www.example.com', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'//www.example.com', '[//www.example.com www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com]'}, {'ftp://ftp.example.com', 'ftp&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'http://www.example.com/', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'http://www.example.com/path', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/path'}, {'www.example.com/foo', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo'}, {'http://www.example.com/foo | link', 'link'}, {'www.example.com/foo | link', 'link'}, {'http://www.example.com/path/', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/path&#x3c;wbr/&#x3e;/'}, {'www.example.com/foo/', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/'}, {'1=http://www.example.com/path?section=17', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/path?section=17'}, {'1=www.example.com/foo?page=42 ', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo?page=42'}, {'http://www.example.com/foo/ | link', 'link'}, {'www.example.com/foo/ | link', 'link'}, -- From Template:URL/testcases (and not already listed above) {'http://', '[http:// ]'}, {'WWW.EXAMPLE.COM', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'https://www.EXAMPLE.cOm', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'HTTPS://www.EXAMPLE.cOm/', '[HTTPS://www.EXAMPLE.cOm/ www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com]'}, {'https://www.example.com/', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com'}, {'http://example.com', 'example&#x3c;wbr/&#x3e;.com'}, {'https://example.com', 'example&#x3c;wbr/&#x3e;.com'}, {'ftp://example.com', 'example&#x3c;wbr/&#x3e;.com'}, {'http://www.example.com/foo/bar', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'http://www.example.com/foo/bar/', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar&#x3c;wbr/&#x3e;/'}, {'http://www.example.com/foO/BaR', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foO&#x3c;wbr/&#x3e;/BaR'}, {'https://www.example.com/foo/bar', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'http://example.com/foo/bar', 'example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'https://example.com/foo/bar', 'example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'example.com/foo/bar', 'example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'www.example.com/foo/bar', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'http://example.com/foo/bar | ', 'example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'1=http://www.example.com?foo=BaR', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com?foo=BaR'}, {'http://www.example.com#fooBaR', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;#fooBaR'}, {'http://www.example.com:8080', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com:8080'}, {'http://www.example.com:8080/foo/bar', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com:8080&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'www.example.com:8080', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com:8080'}, {'www.example.com:8080/foo/bar', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com:8080&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar'}, {'http://www.example.com/foo bar', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo%20bar'}, {'www.example.com/foo bar', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo%20bar'}, {'http://example.com/foo/bar | link', 'link'}, {'https://example.com/foo/bar | link', 'link'}, {'example.com/foo/bar | link', 'link'}, {'www.example.com/foo/bar | link', 'link'}, {'www.example.com/foo/bar | 捦挺挎', '捦挺挎'}, {'www.example.com/foo/捦挺挎/bar | link', 'link'}, {'عمان.icom.museum', 'عمان&#x3c;wbr/&#x3e;.icom&#x3c;wbr/&#x3e;.museum'}, {'http://عمان.icom.museum', 'عمان&#x3c;wbr/&#x3e;.icom&#x3c;wbr/&#x3e;.museum'}, {'1964thetribute.com', '1964thetribute&#x3c;wbr/&#x3e;.com'}, {'1964thetribute.com | 1964thetribute.com', '1964thetribute&#x3c;wbr/&#x3e;.com'}, {'1= http://www.example.com/foo/bar?a=b&#x26;c=d', 'www&#x3c;wbr/&#x3e;.example&#x3c;wbr/&#x3e;.com&#x3c;wbr/&#x3e;/foo&#x3c;wbr/&#x3e;/bar?a=b&#x26;c=d'}, {'1=www.hti.umich.edu/cgi/t/text/pageviewer-idx?c=umhistmath;cc=umhistmath;rgn=full%20text;idno=ABS3153.0001.001;didno=ABS3153.0001.001;view=image;seq=00000140', 'www&#x3c;wbr/&#x3e;.hti&#x3c;wbr/&#x3e;.umich&#x3c;wbr/&#x3e;.edu&#x3c;wbr/&#x3e;/cgi&#x3c;wbr/&#x3e;/t&#x3c;wbr/&#x3e;/text&#x3c;wbr/&#x3e;/pageviewer-idx?c=umhistmath%3Bcc%3Dumhistmath%3Brgn%3Dfull+text%3Bidno%3DABS3153&#x3c;wbr/&#x3e;.0001&#x3c;wbr/&#x3e;.001%3Bdidno%3DABS3153&#x3c;wbr/&#x3e;.0001&#x3c;wbr/&#x3e;.001%3Bview%3Dimage%3Bseq%3D00000140'}, {'http://www.sho.com/site/dexter/home.sho | \'\'Dexter\'\'s official website', '\'\'Dexter\'\'&#x3c;span class="nowrap" style="padding-left:0.1em;"&#x3e;&#x26;#39;&#x3c;/span&#x3e;s official website' }, }   for _, case in ipairs(cases) do        self:preprocess_equals('', '&#x3c;span class="url"&#x3e;' .. case[2] .. '&#x3c;/span&#x3e;', {nowiki=true}) end

self:preprocess_equals('', 'example.com', {nowiki=true}) self:preprocess_equals('', 'http://example.com/foo', {nowiki=true}) end

return p