aboutsummaryrefslogtreecommitdiff
path: root/chrome/content/unittests.js
blob: 095b13b1875be077202a77c08515ca33878ac186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var tests = {
	"Wildcard matches" : {
		run : function(data) { 
			var pattern = data[0],
				url = data[1],
				expected = data[2];
			var parts = expected.split(',');
			var redirectUrl = '';
			if (!(parts.length == 1 && parts[0] == '')) {
				for (var i in parts) {
					redirectUrl += '$' + (parseFloat(i)+1) + ',';
				}
				redirectUrl = redirectUrl.substr(0, redirectUrl.length-1);
			}
			var result = redirector.wildcardMatch(pattern, url, redirectUrl, false); 
			return result == expected;
		},
		
		describe : function(data) { return data[0] + ' matches ' + data[1] + ', matches=' + data[2]; },
		tests : [
			['http://foo*', 'http://foobar.is', 'bar.is'],
			['http://foo*', 'http://foo', ''],
			['*foo*', 'http://foo', 'http://,'],
			['*foo*', 'http://foobar.is', 'http://,bar.is'],
			['http://foo.is', 'http://foo.is', ''],
			['*', 'http://foo.is', 'http://foo.is'],
			['*://foo.is', 'http://foo.is', 'http'],
			['*://foo.is*', 'http://foo.is/bar/baz', 'http,/bar/baz'],
			['*://*oo*bar*', 'http://foo.is/bar/baz', 'http,f,.is/,/baz']
		]
	}
};