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 = {
         '{{#invoke:URL/sandbox|url}}',
         '{{#invoke:URL/sandbox|url|}}',
         '{{#invoke:URL/sandbox|url||}}',
     }
     text = self.frame:expandTemplate{ title = 'tlx', args = { 'URL', &quot;''example.com''&quot;, &quot;''optional display text''&quot; } }
     for _, case in ipairs(cases) do
         self:preprocess_equals(case, text)
     end
         
     cases = {
     	{'http://www.example.com/foo/bar?a=b&amp;c=d', '[http://www.example.com/foo/bar?a=b&amp;c=d www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar?a=b&amp;c=d]'},
         {'EXAMPLE.com', '[http://EXAMPLE.com example&lt;wbr/&gt;.com]'},
         {'example.com', '[http://example.com example&lt;wbr/&gt;.com]'},
         {'www.example.com', '[http://www.example.com www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'http://www.example.com', '[http://www.example.com www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'https://www.example.com', '[https://www.example.com www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'ftp://www.example.com', '[ftp://www.example.com www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'//www.example.com', '[//www.example.com www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'ftp://ftp.example.com', '[ftp://ftp.example.com ftp&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'http://www.example.com/', '[http://www.example.com/ www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'http://www.example.com/path', '[http://www.example.com/path www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/path]'},
         {'www.example.com/foo', '[http://www.example.com/foo www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/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&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/path&lt;wbr/&gt;/]'},
         {'www.example.com/foo/', '[http://www.example.com/foo/ www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/]'},
         {'1=http://www.example.com/path?section=17', '[http://www.example.com/path?section=17 www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/path?section=17]'},
         {'1=www.example.com/foo?page=42 ', '[http://www.example.com/foo?page=42 www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/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]'},
         
         -- From [[Template:URL/testcases]] (and not already listed above)
         {'http://', '[http:// ]'},
         {'WWW.EXAMPLE.COM', '[http://WWW.EXAMPLE.COM www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'https://www.EXAMPLE.cOm', '[https://www.EXAMPLE.cOm www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'HTTPS://www.EXAMPLE.cOm/', '[HTTPS://www.EXAMPLE.cOm/ www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'https://www.example.com/', '[https://www.example.com/ www&lt;wbr/&gt;.example&lt;wbr/&gt;.com]'},
         {'http://example.com', '[http://example.com example&lt;wbr/&gt;.com]'},
         {'https://example.com', '[https://example.com example&lt;wbr/&gt;.com]'},
         {'ftp://example.com', '[ftp://example.com example&lt;wbr/&gt;.com]'},
         {'http://www.example.com/foo/bar', '[http://www.example.com/foo/bar www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'http://www.example.com/foo/bar/', '[http://www.example.com/foo/bar/ www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar&lt;wbr/&gt;/]'},
         {'http://www.example.com/foO/BaR', '[http://www.example.com/foO/BaR www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foO&lt;wbr/&gt;/BaR]'},
         {'https://www.example.com/foo/bar', '[https://www.example.com/foo/bar www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'http://example.com/foo/bar', '[http://example.com/foo/bar example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'https://example.com/foo/bar', '[https://example.com/foo/bar example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'example.com/foo/bar', '[http://example.com/foo/bar example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'www.example.com/foo/bar', '[http://www.example.com/foo/bar www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'http://example.com/foo/bar | ', '[http://example.com/foo/bar example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'1=http://www.example.com?foo=BaR', '[http://www.example.com?foo=BaR www&lt;wbr/&gt;.example&lt;wbr/&gt;.com?foo=BaR]'},
         {'http://www.example.com#fooBaR', '[http://www.example.com#fooBaR www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;#fooBaR]'},
         {'http://www.example.com:8080', '[http://www.example.com:8080 www&lt;wbr/&gt;.example&lt;wbr/&gt;.com:8080]'},
         {'http://www.example.com:8080/foo/bar', '[http://www.example.com:8080/foo/bar www&lt;wbr/&gt;.example&lt;wbr/&gt;.com:8080&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'www.example.com:8080', '[http://www.example.com:8080 www&lt;wbr/&gt;.example&lt;wbr/&gt;.com:8080]'},
         {'www.example.com:8080/foo/bar', '[http://www.example.com:8080/foo/bar www&lt;wbr/&gt;.example&lt;wbr/&gt;.com:8080&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar]'},
         {'http://www.example.com/foo bar', '[http://www.example.com/foo%20bar www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo%20bar]'},
         {'www.example.com/foo bar', '[http://www.example.com/foo%20bar www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo%20bar]'},
         {'http://example.com/foo/bar | link', '[http://example.com/foo/bar link]'},
         {'https://example.com/foo/bar | link', '[https://example.com/foo/bar link]'},
         {'example.com/foo/bar | link', '[http://example.com/foo/bar link]'},
         {'www.example.com/foo/bar | link', '[http://www.example.com/foo/bar link]'},
         {'www.example.com/foo/bar | 捦挺挎', '[http://www.example.com/foo/bar 捦挺挎]'},
         {'www.example.com/foo/捦挺挎/bar | link', '[http://www.example.com/foo/捦挺挎/bar link]'},
         {'عمان.icom.museum', '[http://عمان.icom.museum عمان&lt;wbr/&gt;.icom&lt;wbr/&gt;.museum]'},
         {'http://عمان.icom.museum', '[http://عمان.icom.museum عمان&lt;wbr/&gt;.icom&lt;wbr/&gt;.museum]'},
         {'1964thetribute.com', '[http://1964thetribute.com 1964thetribute&lt;wbr/&gt;.com]'},
         {'1964thetribute.com | 1964thetribute.com', '[http://1964thetribute.com 1964thetribute&lt;wbr/&gt;.com]'},
         {'1= http://www.example.com/foo/bar?a=b&amp;c=d', '[http://www.example.com/foo/bar?a=b&amp;c=d www&lt;wbr/&gt;.example&lt;wbr/&gt;.com&lt;wbr/&gt;/foo&lt;wbr/&gt;/bar?a=b&amp;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',
             '[http://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&lt;wbr/&gt;.hti&lt;wbr/&gt;.umich&lt;wbr/&gt;.edu&lt;wbr/&gt;/cgi&lt;wbr/&gt;/t&lt;wbr/&gt;/text&lt;wbr/&gt;/pageviewer-idx?c=umhistmath%3Bcc%3Dumhistmath%3Brgn%3Dfull+text%3Bidno%3DABS3153&lt;wbr/&gt;.0001&lt;wbr/&gt;.001%3Bdidno%3DABS3153&lt;wbr/&gt;.0001&lt;wbr/&gt;.001%3Bview%3Dimage%3Bseq%3D00000140]'},
         {'http://www.sho.com/site/dexter/home.sho | \'\'Dexter\'\'{{\'}}s official website',
         	'[http://www.sho.com/site/dexter/home.sho \'\'Dexter\'\'&lt;span class=&quot;nowrap&quot; style=&quot;padding-left:0.1em;&quot;&gt;&amp;#39;&lt;/span&gt;s official website]' },
     }
     
     for _, case in ipairs(cases) do
         self:preprocess_equals('{{#invoke:URL/sandbox|url|' .. case[1] .. '}}', '&lt;span class=&quot;url&quot;&gt;' .. case[2] .. '&lt;/span&gt;', {nowiki=true})
     end
 
     self:preprocess_equals('{{#invoke:URL/sandbox|url|2= example.com}}', 'example.com', {nowiki=true})
     self:preprocess_equals('{{#invoke:URL/sandbox|url|2= http://example.com/foo}}', 'http://example.com/foo', {nowiki=true})
 end