Module:URL/testcases

-- Unit tests for [[Module:URL]]. Click talk page to run tests.
local p = require('Module:UnitTests')
 
function p:test_url()
    local text = self.frame:expandTemplate{ title = 'tlx', args = { 'URL', "''example.com''", "''optional display text''" } }
    self:preprocess_equals_sandbox_many('{{#invoke:URL', 'url', {
        {'', text},
        {'|', text},
        {'||', text},
    }, {combined=true})
        
    local cases = {
    	{'http://www.example.com/foo/bar?a=b&c=d', '[http://www.example.com/foo/bar?a=b&c=d www<wbr/>.example<wbr/>.com<wbr/>/foo<wbr/>/bar?a=b&c=d]'},
        {'EXAMPLE.com', '[http://EXAMPLE.com example<wbr/>.com]'},
        {'example.com', '[http://example.com example<wbr/>.com]'},
        {'www.example.com', '[http://www.example.com www<wbr/>.example<wbr/>.com]'},
        {'http://www.example.com', '[http://www.example.com www<wbr/>.example<wbr/>.com]'},
        {'https://www.example.com', '[https://www.example.com www<wbr/>.example<wbr/>.com]'},
        {'ftp://www.example.com', '[ftp://www.example.com www<wbr/>.example<wbr/>.com]'},
        {'//www.example.com', '[//www.example.com www<wbr/>.example<wbr/>.com]'},
        {'ftp://ftp.example.com', '[ftp://ftp.example.com ftp<wbr/>.example<wbr/>.com]'},
        {'http://www.example.com/', '[http://www.example.com/ www<wbr/>.example<wbr/>.com]'},
        {'http://www.example.com/path', '[http://www.example.com/path www<wbr/>.example<wbr/>.com<wbr/>/path]'},
        {'www.example.com/foo', '[http://www.example.com/foo www<wbr/>.example<wbr/>.com<wbr/>/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<wbr/>.example<wbr/>.com<wbr/>/path<wbr/>/]'},
        {'www.example.com/foo/', '[http://www.example.com/foo/ www<wbr/>.example<wbr/>.com<wbr/>/foo<wbr/>/]'},
        {'1=http://www.example.com/path?section=17', '[http://www.example.com/path?section=17 www<wbr/>.example<wbr/>.com<wbr/>/path?section=17]'},
        {'1=www.example.com/foo?page=42 ', '[http://www.example.com/foo?page=42 www<wbr/>.example<wbr/>.com<wbr/>/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<wbr/>.example<wbr/>.com]'},
        {'https://www.EXAMPLE.cOm', '[https://www.EXAMPLE.cOm www<wbr/>.example<wbr/>.com]'},
        {'HTTPS://www.EXAMPLE.cOm/', '[HTTPS://www.EXAMPLE.cOm/ www<wbr/>.example<wbr/>.com]'},
        {'https://www.example.com/', '[https://www.example.com/ www<wbr/>.example<wbr/>.com]'},
        {'http://example.com', '[http://example.com example<wbr/>.com]'},
        {'https://example.com', '[https://example.com example<wbr/>.com]'},
        {'ftp://example.com', '[ftp://example.com example<wbr/>.com]'},
        {'http://www.example.com/foo/bar', '[http://www.example.com/foo/bar www<wbr/>.example<wbr/>.com<wbr/>/foo<wbr/>/bar]'},
        {'http://www.example.com/foo/bar/', '[http://www.example.com/foo/bar/ www<wbr/>.example<wbr/>.com<wbr/>/foo<wbr/>/bar<wbr/>/]'},
        {'http://www.example.com/foO/BaR', '[http://www.example.com/foO/BaR www<wbr/>.example<wbr/>.com<wbr/>/foO<wbr/>/BaR]'},
        {'https://www.example.com/foo/bar', '[https://www.example.com/foo/bar www<wbr/>.example<wbr/>.com<wbr/>/foo<wbr/>/bar]'},
        {'http://example.com/foo/bar', '[http://example.com/foo/bar example<wbr/>.com<wbr/>/foo<wbr/>/bar]'},
        {'https://example.com/foo/bar', '[https://example.com/foo/bar example<wbr/>.com<wbr/>/foo<wbr/>/bar]'},
        {'example.com/foo/bar', '[http://example.com/foo/bar example<wbr/>.com<wbr/>/foo<wbr/>/bar]'},
        {'www.example.com/foo/bar', '[http://www.example.com/foo/bar www<wbr/>.example<wbr/>.com<wbr/>/foo<wbr/>/bar]'},
        {'http://example.com/foo/bar | ', '[http://example.com/foo/bar example<wbr/>.com<wbr/>/foo<wbr/>/bar]'},
        {'1=http://www.example.com?foo=BaR', '[http://www.example.com?foo=BaR www<wbr/>.example<wbr/>.com?foo=BaR]'},
        {'http://www.example.com#fooBaR', '[http://www.example.com#fooBaR www<wbr/>.example<wbr/>.com<wbr/>#fooBaR]'},
        {'http://www.example.com:8080', '[http://www.example.com:8080 www<wbr/>.example<wbr/>.com:8080]'},
        {'http://www.example.com:8080/foo/bar', '[http://www.example.com:8080/foo/bar www<wbr/>.example<wbr/>.com:8080<wbr/>/foo<wbr/>/bar]'},
        {'www.example.com:8080', '[http://www.example.com:8080 www<wbr/>.example<wbr/>.com:8080]'},
        {'www.example.com:8080/foo/bar', '[http://www.example.com:8080/foo/bar www<wbr/>.example<wbr/>.com:8080<wbr/>/foo<wbr/>/bar]'},
        {'http://www.example.com/foo bar', '[http://www.example.com/foo%20bar www<wbr/>.example<wbr/>.com<wbr/>/foo%20bar]'},
        {'www.example.com/foo bar', '[http://www.example.com/foo%20bar www<wbr/>.example<wbr/>.com<wbr/>/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 عمان<wbr/>.icom<wbr/>.museum]'},
        {'http://عمان.icom.museum', '[http://عمان.icom.museum عمان<wbr/>.icom<wbr/>.museum]'},
        {'1964thetribute.com', '[http://1964thetribute.com 1964thetribute<wbr/>.com]'},
        {'1964thetribute.com | 1964thetribute.com', '[http://1964thetribute.com 1964thetribute<wbr/>.com]'},
        {'1= http://www.example.com/foo/bar?a=b&c=d', '[http://www.example.com/foo/bar?a=b&c=d www<wbr/>.example<wbr/>.com<wbr/>/foo<wbr/>/bar?a=b&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<wbr/>.hti<wbr/>.umich<wbr/>.edu<wbr/>/cgi<wbr/>/t<wbr/>/text<wbr/>/pageviewer-idx?c=umhistmath%3Bcc%3Dumhistmath%3Brgn%3Dfull+text%3Bidno%3DABS3153<wbr/>.0001<wbr/>.001%3Bdidno%3DABS3153<wbr/>.0001<wbr/>.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\'\'<span class="nowrap" style="padding-left:0.1em;">&#39;</span>s official website]' },
    }
    
    for _, case in ipairs(cases) do
        case[2] = '<span class="url">' .. case[2] .. '</span>'
    end
	cases[#cases + 1] = {'2= example.com', 'example.com'}
	cases[#cases + 1] = {'2= http://example.com/foo', 'http://example.com/foo'}
	self:preprocess_equals_sandbox_many('{{#invoke:URL', 'url', cases, {combined=true})
end

function p:test_nested_url()
	self:preprocess_equals_sandbox_many('{{#invoke:URL', 'url',
		{
			-- Tests the case of {{url|{{url|www.google.com}}}}
			{'<span class="url">[http://www.google.com www<wbr/>.google<wbr/>.com]</span>', '<span class="url">[http://www.google.com www<wbr/>.google<wbr/>.com]</span>'}
		}, {nowiki = 1}
	)
end


return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.