aboutsummaryrefslogtreecommitdiff
path: root/chrome/content/unittests.js
diff options
context:
space:
mode:
authorEinar Egilsson2009-09-15 08:00:03 +0000
committerEinar Egilsson2009-09-15 08:00:03 +0000
commit50d488f4c2137206e63f291ff99c4f09d177d31d (patch)
tree9b98d5382de8803c00fbeb5a32041fa43582cc0f /chrome/content/unittests.js
parent0225b1c8035a1c03dafa4c971d21facc76dbc2de (diff)
Fixed the wildcard match and added a bunch of unit tests.
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@247 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content/unittests.js')
-rw-r--r--chrome/content/unittests.js31
1 files changed, 26 insertions, 5 deletions
diff --git a/chrome/content/unittests.js b/chrome/content/unittests.js
index c532d3f..095b13b 100644
--- a/chrome/content/unittests.js
+++ b/chrome/content/unittests.js
@@ -1,12 +1,33 @@
var tests = {
"Wildcard matches" : {
- run : function(data) { return redirector.wildcardMatch(data[0], data[1], 'abc', false); },
- describe : function(data) { return data[0] + ' matches ' + data[1]; },
+ 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'],
- ['http://foo*', 'http://foo'],
- ['*foo*', 'http://foo']
+ ['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']
]
}
};