Mô đun:URL/testcases

-- Các trường hợp kiểm thử đơn vị cho Mô đun:URL. Bấm vào trang thảo luận để chạy các trường hợp kiểm thử.
local p = require('Mô đun:UnitTests')

function p:test_url()
local cases = {
'url',
,
,
,
}
text = self.frame:expandTemplate{ title = 'tlx', args = { 'URL', "example.com", "văn bản hiển thị tùy chọn" } }
for _, case in ipairs(cases) do
self:preprocess_equals(case, text)
end

cases = {
{'EXAMPLE.com', ' example.com'},
{'example.com', ' example.com'},
{'www.example.com', ' www.example.com'},
{'http://www.example.com', ' www.example.com'},
{'https://www.example.com', ' www.example.com'},
{'ftp://www.example.com', ' www.example.com'},
{'//www.example.com', '//www.example.com www.example.com'},
{'ftp://ftp.example.com', ' ftp.example.com'},
{'http://www.example.com/', ' www.example.com'},
{'http://www.example.com/path', ' www.example.com/path'},
{'www.example.com/foo', ' www.example.com/foo'},
{'http://www.example.com/foo | link', ' link'},
{'www.example.com/foo | link', ' link'},
{'http://www.example.com/path/', ' www.example.com/path/'},
{'www.example.com/foo/', ' www.example.com/foo/'},
{'1=http://www.example.com/path?section=17', ' www.example.com/path?section=17'},
{'1=www.example.com/foo?page=42 ', ' www.example.com/foo?page=42'},
{'http://www.example.com/foo/ | link', ' link'},
{'www.example.com/foo/ | link', ' link'},

-- Từ Bản mẫu:URL/testcases (và chưa được liệt kê ở trên)
{'http://', ' '},
{'WWW.EXAMPLE.COM', ' www.example.com'},
{'https://www.EXAMPLE.cOm', ' www.example.com'},
{'HTTPS://www.EXAMPLE.cOm/', ' www.example.com'},
{'https://www.example.com/', ' www.example.com'},
{'http://example.com', ' example.com'},
{'https://example.com', ' example.com'},
{'ftp://example.com', ' example.com'},
{'http://www.example.com/foo/bar', ' www.example.com/foo/bar'},
{'http://www.example.com/foo/bar/', ' www.example.com/foo/bar/'},
{'http://www.example.com/foO/BaR', ' www.example.com/foO/BaR'},
{'https://www.example.com/foo/bar', ' www.example.com/foo/bar'},
{'http://example.com/foo/bar', ' example.com/foo/bar'},
{'https://example.com/foo/bar', ' example.com/foo/bar'},
{'example.com/foo/bar', ' example.com/foo/bar'},
{'www.example.com/foo/bar', ' www.example.com/foo/bar'},
{'http://example.com/foo/bar | ', ' example.com/foo/bar'},
{'1=http://www.example.com?foo=BaR', ' www.example.com?foo=BaR'},
{'http://www.example.com#fooBaR', ' www.example.com#fooBaR'},
{'http://www.example.com:8080', ' www.example.com:8080'},
{'http://www.example.com:8080/foo/bar', ' www.example.com:8080/foo/bar'},
{'www.example.com:8080', ' www.example.com:8080'},
{'www.example.com:8080/foo/bar', ' www.example.com:8080/foo/bar'},
{'http://www.example.com/foo bar', ' www.example.com/foo%20bar'},
{'www.example.com/foo bar', ' www.example.com/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', ' عمان.icom.museum'},
{'http://عمان.icom.museum', ' عمان.icom.museum'},
{'1964thetribute.com', ' 1964thetribute.com'},
{'1964thetribute.com | 1964thetribute.com', ' 1964thetribute.com'},
{'1= http://www.example.com/foo/bar?a=b&c=d', ' www.example.com/foo/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',
' www.hti.umich.edu/cgi/t/text/pageviewer-idx?c=umhistmath%3Bcc%3Dumhistmath%3Brgn%3Dfull+text%3Bidno%3DABS3153.0001.001%3Bdidno%3DABS3153.0001.001%3Bview%3Dimage%3Bseq%3D00000140'},
{'http://www.sho.com/site/dexter/home.sho | \'\'Dexter\'\'s trang web chính thức',
	' \'\'Dexter\'\s trang web chính thức' },
}

for _, case in ipairs(cases) do
self:preprocess_equals('#gọi:URL/sandbox|url|' .. case1 .. ,  .. case2 .. , {nowiki=true})
end
self:preprocess_equals('2= example.com', 'example.com', {nowiki=true})
self:preprocess_equals('2= http://example.com/foo', 'http://example.com/foo', {nowiki=true})
end
return p