"use strict";

function TestURLValidator()
{
	throw new Error("Static class.");
}


TestURLValidator.strNoException=null;
TestURLValidator.strURLValidatorException="URLValidatorException";
TestURLValidator.strDomainNameValidatorException="DomainNameValidatorException";

TestURLValidator.arrValidURLs=[
	["http://foo.com/blah_blah", TestURLValidator.strNoException, 0], 
	["http://foo.com/blah_blah/", TestURLValidator.strNoException, 0], 
	["http://foo.com/blah_blah_(wikipedia)", TestURLValidator.strNoException, 0], 
	["http://foo.com/blah_blah_(wikipedia)_(again)", TestURLValidator.strNoException, 0],
	["http://www.example.com/wpstyle/?p=364", TestURLValidator.strNoException, 0], 
	["https://www.example.com/foo/?bar=b****az&inga=42&qu#ux", TestURLValidator.strNoException, 0],
	["http://userid@example.com", TestURLValidator.strNoException, 0],
	["http://userid@example.com/", TestURLValidator.strNoException, 0], 
	["http://userid@example.com:8080", TestURLValidator.strNoException, 0], 
	["http://userid@example.com:8080/", TestURLValidator.strNoException, 0],
	["http://foo.com/(something)?after=parens", TestURLValidator.strNoException, 0], 
	["http://j.mp", TestURLValidator.strNoException, 0], 
	["http://1337.net", TestURLValidator.strNoException, 0], 
	["http://a.b-c.de", TestURLValidator.strNoException, 0],
	["http://a.b--c.de/", TestURLValidator.strNoException, 0] 
];

TestURLValidator.arrInvalidURLs=[
	["//", TestURLValidator.strURLValidatorException, 10], 
	["//a", TestURLValidator.strURLValidatorException, 10], 
	["///a", TestURLValidator.strURLValidatorException, 10], 
	["///", TestURLValidator.strURLValidatorException, 10],  
	["foo.com", TestURLValidator.strURLValidatorException, 10],
	["http:www.google.ro/gigel", TestURLValidator.strURLValidatorException, 2],
	["http://userid:password@example.com", TestURLValidator.strURLValidatorException, 3],
	["http://userid:password@example.com/", TestURLValidator.strURLValidatorException, 3],
	["http://userid:password@example.com:8080", TestURLValidator.strURLValidatorException, 3],
	["http://userid:password@example.com:8080/", TestURLValidator.strURLValidatorException, 3],
	["http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", TestURLValidator.strURLValidatorException, 4],
	["http://gigel.com:70123/", TestURLValidator.strURLValidatorException, 5],
	["http://code.google.com/events/#&product=browser", TestURLValidator.strURLValidatorException, 6],
	["http://foo.com/blah_(wikipedia)#cite-1", TestURLValidator.strURLValidatorException, 6],
	["http://foo.com/blah_(wikipedia)_blah#cite-1", TestURLValidator.strURLValidatorException, 6],
	["http://foo.com/unicode_(âœª)_in_parens", TestURLValidator.strURLValidatorException, 6],
	["http://gigel.com/ceva?atunci¤°#altceva", TestURLValidator.strURLValidatorException, 7],
	["http://gigel.com/ceva?atunci#altceva¤°altfel", TestURLValidator.strURLValidatorException, 8],
	["ftp://foo.bar/baz", TestURLValidator.strURLValidatorException, 9],
	["rdar://1234", TestURLValidator.strURLValidatorException, 9],
	["h://test", TestURLValidator.strURLValidatorException, 9],
	[":// should fail", TestURLValidator.strURLValidatorException, 9], 
	["ftps://foo.bar/", TestURLValidator.strURLValidatorException, 9]
];
	
TestURLValidator.arrInvalidDomainNames=[
	["http://223.255.255.254", TestURLValidator.strDomainNameValidatorException, 1],
	["http://foo.bar/?q=Test%20URL-encoded%20stuff", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://Ù…Ø«Ø§Ù„.Ø¥Ø®ØªØ¨Ø§Ø±", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://ä¾‹å­.æµ‹è¯•", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://à¤‰à¤¦à¤¾à¤¹à¤°à¤£.à¤ªà¤°à¥€à¤•à¥à¤·à¤¾", TestURLValidator.strDomainNameValidatorException, 1],
	["http://142.42.1.1/", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://142.42.1.1:8080/", TestURLValidator.strDomainNameValidatorException, 1],
	["http://", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://.", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://..", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://../", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://?", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://??", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://??/", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://#", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://##", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://##/", TestURLValidator.strDomainNameValidatorException, 1],
	["http://foo.bar?q=Spaces should be encoded", TestURLValidator.strDomainNameValidatorException, 1],
	["http:///a", TestURLValidator.strDomainNameValidatorException, 1],
	["http://foo.bar/foo(bar)baz quux", TestURLValidator.strDomainNameValidatorException, 1],
	["http://-error-.invalid/", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://0.0.0.0", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://10.1.1.0", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://10.1.1.255", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://224.1.1.1", TestURLValidator.strDomainNameValidatorException, 1],
	["http://1.1.1.1.1", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://123.123.123", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://3628126748", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://.www.foo.bar/", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://www.foo.bar./", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://.www.foo.bar./", TestURLValidator.strDomainNameValidatorException, 1],
	["http://10.1.1.1", TestURLValidator.strDomainNameValidatorException, 1], 
	["http://10.1.1.254", TestURLValidator.strDomainNameValidatorException, 1],
	["http://lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala.com", TestURLValidator.strDomainNameValidatorException, 2],
	["http://lala.lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"
			+ "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalala", TestURLValidator.strDomainNameValidatorException, 1],	// 3, if bAllowNonIANATLD = true
	["http://lala./", TestURLValidator.strDomainNameValidatorException, 1], // 4, if bAllowNonIANATLD = true
	["http://â˜º.damowmow.com/", TestURLValidator.strDomainNameValidatorException, 5],
	["http://âž¡.ws/ä¨¹", TestURLValidator.strDomainNameValidatorException, 5], 
	["http://âŒ˜.ws", TestURLValidator.strDomainNameValidatorException, 5], 
	["http://âŒ˜.ws/", TestURLValidator.strDomainNameValidatorException, 5],
	["http://âœªdf.ws/123", TestURLValidator.strDomainNameValidatorException, 5],
	["http:// shouldfail.com", TestURLValidator.strDomainNameValidatorException, 5],
	["http://-a.b.co", TestURLValidator.strDomainNameValidatorException, 5],
	["http://a.b-.co", TestURLValidator.strDomainNameValidatorException, 5]
];


TestURLValidator.test=function(arrURLs)
{
	var index=0;
	
	for(var key in arrURLs)
	{
		console.log("%i -> %s", index++, arrURLs[key][0]);
		
		if (arrURLs[key][1]==TestURLValidator.strNoException)
			console.log(">>>>> NO ERROR CODE");
		else 
			console.log(">>>>> Expected ERROR: %s - code: %i", arrURLs[key][1], arrURLs[key][2]);
			
		console.log(URLValidator.assertValid(arrURLs[key][0], false, false, false));
	}
}
