Index: qunit/tests/baseDomain.js |
=================================================================== |
--- a/qunit/tests/baseDomain.js |
+++ b/qunit/tests/baseDomain.js |
@@ -1,28 +1,126 @@ |
(function() |
{ |
module("URL/host tools"); |
test("Host name extraction", function() |
{ |
var tests = [ |
+ [null, ""], |
+ ["/foo/bar", ""], |
["http://example.com/", "example.com"], |
["http://example.com:8000/", "example.com"], |
- ["http://foo:bar@example.com:8000/", "example.com"], |
+ ["http://foo:bar@example.com:8000/foo:bar/bas", "example.com"], |
["ftp://example.com/", "example.com"], |
["http://1.2.3.4:8000/", "1.2.3.4"], |
["http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]/", "2001:0db8:85a3:0000:0000:8a2e:0370:7334"], |
["http://[2001::7334]:8000/test@foo.example.com/bar", "2001::7334"], |
]; |
for (var i = 0; i < tests.length; i++) |
equal(extractHostFromURL(tests[i][0]), tests[i][1], tests[i][0]); |
}); |
+ test("Invalid URI recognition", function() |
+ { |
+ var tests = [ |
+ null, |
+ "", |
+ "http:", |
+ "http:foo.bar/", |
+ "http://foo.bar" |
+ ]; |
+ for (var i = 0; i < tests.length; i++) |
+ { |
+ raises(function() |
+ { |
+ return new URI(tests[i]); |
+ }, tests[i]); |
+ } |
+ }); |
+ |
+ test("URI parsing", function() |
+ { |
+ var tests = [ |
+ ["http://example.com/", { |
+ scheme: "http", |
+ host: "example.com", |
+ asciiHost: "example.com", |
+ hostPort: "example.com", |
+ port: -1, |
+ path: "/", |
+ prePath: "http://example.com" |
+ }], |
+ ["http://example.com:8000/", { |
+ scheme: "http", |
+ host: "example.com", |
+ asciiHost: "example.com", |
+ hostPort: "example.com:8000", |
+ port: 8000, |
+ path: "/", |
+ prePath: "http://example.com:8000" |
+ }], |
+ ["http://foo:bar@\u0440\u043E\u0441\u0441\u0438\u044F.\u0440\u0444:8000/foo:bar/bas", { |
+ scheme: "http", |
+ host: "\u0440\u043E\u0441\u0441\u0438\u044F.\u0440\u0444", |
+ asciiHost: "xn--h1alffa9f.xn--p1ai", |
+ hostPort: "\u0440\u043E\u0441\u0441\u0438\u044F.\u0440\u0444:8000", |
+ port: 8000, |
+ path: "/foo:bar/bas", |
+ prePath: "http://foo:bar@\u0440\u043E\u0441\u0441\u0438\u044F.\u0440\u0444:8000" |
+ }], |
+ ["ftp://m\xFCller.de/", { |
+ scheme: "ftp", |
+ host: "m\xFCller.de", |
+ asciiHost: "xn--mller-kva.de", |
+ hostPort: "m\xFCller.de", |
+ port: -1, |
+ path: "/", |
+ prePath: "ftp://m\xFCller.de" |
+ }], |
+ ["http://1.2.3.4:8000/", { |
+ scheme: "http", |
+ host: "1.2.3.4", |
+ asciiHost: "1.2.3.4", |
+ hostPort: "1.2.3.4:8000", |
+ port: 8000, |
+ path: "/", |
+ prePath: "http://1.2.3.4:8000" |
+ }], |
+ ["http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]/", { |
+ scheme: "http", |
+ host: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", |
+ asciiHost: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", |
+ hostPort: "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", |
+ port: -1, |
+ path: "/", |
+ prePath: "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]" |
+ }], |
+ ["http://[2001::7334]:8000/test@foo.example.com/bar", { |
+ scheme: "http", |
+ host: "2001::7334", |
+ asciiHost: "2001::7334", |
+ hostPort: "[2001::7334]:8000", |
+ port: 8000, |
+ path: "/test@foo.example.com/bar", |
+ prePath: "http://[2001::7334]:8000" |
+ }], |
+ ]; |
+ |
+ for (var i = 0; i < tests.length; i++) |
+ { |
+ var url = tests[i][0]; |
+ var uri = new URI(url); |
+ equal(uri.spec, url, "URI(" + url + ").spec"); |
+ for (var k in tests[i][1]) |
+ equal(uri[k], tests[i][1][k], "URI(" + url + ")." + k); |
+ } |
+ }); |
+ |
test("Determining base domain", function() |
{ |
var tests = [ |
["com", "com"], |
["example.com", "example.com"], |
["www.example.com", "example.com"], |
["www.example.com.", "example.com"], |
["www.example.co.uk", "example.co.uk"], |