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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
//// $Id$
var tests = {
"Wildcard matches" : {
run : function(data,log) {
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 redirect = new Redirect(null, pattern, null, redirectUrl, Redirect.WILDCARD, null);
var result = redirect.getMatch(url);
return { passed: result.isMatch && (result.redirectTo == expected), message : "Expected '" + expected + "', actual was '" + result.redirectTo + "'"};
},
describe : function(data) { return data[0] + ' == ' + data[1] + ', matches=' + data[2]; },
tests : [
['http://foo*', 'http://foobar.is', 'bar.is'],
['http://foo*', 'http://foo', ''],
['*://foo.is', 'http://foo.is', 'http'],
['*http://foo.is', 'http://foo.is', ''],
['http*foo*', 'http://foobar.is', '://,bar.is'],
['http*foo*', 'http://foo', '://,'],
['*://f*.is', 'http://foo.is', 'http,oo'],
['*http://f*.is', 'http://foo.is', ',oo'],
['*foo*', 'http://foo', 'http://,'],
['*foo*', 'foobar.is', ',bar.is'],
['*foo*', 'http://foobar.is', 'http://,bar.is'],
['http://foo.is', 'http://foo.is', ''],
['*', 'http://foo.is', 'http://foo.is'],
['*://*oo*bar*', 'http://foo.is/bar/baz', 'http,f,.is/,/baz'],
['*://**oo*bar*', 'http://foo.is/bar/baz', 'http,,f,.is/,/baz'],
]
},
"Regex matches" : {
run : function(data,log) {
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 redirect = new Redirect(null, pattern, null, redirectUrl, Redirect.REGEX, null);
var result = redirect.getMatch(url);
return { passed: result.isMatch && result.redirectTo == expected, message : "Expected '" + expected + "', actual was '" + result.redirectTo + "'"};
},
describe : function(data) { return data[0] + ' == ' + data[1] + ', matches=' + data[2]; },
tests : [
['http://foo(.*)', 'http://foobar.is', 'bar.is'],
['http://foo(.*)', 'http://foo', ''],
['(.*)://foo.is', 'http://foo.is', 'http'],
['(.*)http://foo\\.is', 'http://foo.is', ''],
['http(.*)foo(.*)', 'http://foobar.is', '://,bar.is'],
['http(.*)foo(.*)', 'http://foo', '://,'],
['(.*)://f(.*)\\.is', 'http://foo.is', 'http,oo'],
['(.*)http://f(.*)\\.is', 'http://foo.is', ',oo'],
['(.*)foo(.*)', 'http://foo', 'http://,'],
['(.*)foo(.*)', 'foobar.is', ',bar.is'],
['(.*)foo(.*)', 'http://foobar.is', 'http://,bar.is'],
['http://foo\.is', 'http://foo.is', ''],
['(.*)', 'http://foo.is', 'http://foo.is'],
['(.*)://(.*)oo(.*)bar(.*)', 'http://foo.is/bar/baz', 'http,f,.is/,/baz'],
['(.*)://(.*?)(.*)oo(.*)bar(.*)', 'http://foo.is/bar/baz', 'http,,f,.is/,/baz'],
]
}
};
|