| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('uriTest'); | 5 #library('uriTest'); |
| 6 | 6 |
| 7 #import('../../lib/utf/utf.dart'); |
| 7 #import('../../lib/uri/uri.dart'); | 8 #import('../../lib/uri/uri.dart'); |
| 8 | 9 |
| 9 testUri(String uri, bool isAbsolute) { | 10 testUri(String uri, bool isAbsolute) { |
| 10 Expect.equals(isAbsolute, new Uri.fromString(uri).isAbsolute()); | 11 Expect.equals(isAbsolute, new Uri.fromString(uri).isAbsolute()); |
| 11 Expect.stringEquals(uri, new Uri.fromString(uri).toString()); | 12 Expect.stringEquals(uri, new Uri.fromString(uri).toString()); |
| 12 } | 13 } |
| 13 | 14 |
| 15 testEncodeDecode(String orig, String encoded) { |
| 16 var e = encodeUri(orig); |
| 17 Expect.stringEquals(encoded, e); |
| 18 var d = decodeUri(encoded); |
| 19 Expect.stringEquals(orig, d); |
| 20 } |
| 21 |
| 22 testEncodeDecodeComponent(String orig, String encoded) { |
| 23 var e = encodeUriComponent(orig); |
| 24 Expect.stringEquals(encoded, e); |
| 25 var d = decodeUriComponent(encoded); |
| 26 Expect.stringEquals(orig, d); |
| 27 } |
| 28 |
| 14 main() { | 29 main() { |
| 15 testUri("http:", true); | 30 testUri("http:", true); |
| 16 testUri("file://", true); | 31 testUri("file://", true); |
| 17 testUri("file", false); | 32 testUri("file", false); |
| 18 testUri("http://user@example.com:80/fisk?query=89&hest=silas", true); | 33 testUri("http://user@example.com:80/fisk?query=89&hest=silas", true); |
| 19 testUri("http://user@example.com:80/fisk?query=89&hest=silas#fragment", | 34 testUri("http://user@example.com:80/fisk?query=89&hest=silas#fragment", |
| 20 false); | 35 false); |
| 21 Expect.stringEquals("http://user@example.com:80/a/b/c?query#fragment", | 36 Expect.stringEquals("http://user@example.com:80/a/b/c?query#fragment", |
| 22 const Uri("http", "user", "example.com", 80, "/a/b/c", | 37 const Uri("http", "user", "example.com", 80, "/a/b/c", |
| 23 "query", "fragment").toString()); | 38 "query", "fragment").toString()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 base.resolve("g?y/../x").toString()); | 98 base.resolve("g?y/../x").toString()); |
| 84 Expect.stringEquals("http://a/b/c/g#s/./x", | 99 Expect.stringEquals("http://a/b/c/g#s/./x", |
| 85 base.resolve("g#s/./x").toString()); | 100 base.resolve("g#s/./x").toString()); |
| 86 Expect.stringEquals("http://a/b/c/g#s/../x", | 101 Expect.stringEquals("http://a/b/c/g#s/../x", |
| 87 base.resolve("g#s/../x").toString()); | 102 base.resolve("g#s/../x").toString()); |
| 88 Expect.stringEquals("http:g", base.resolve("http:g").toString()); | 103 Expect.stringEquals("http:g", base.resolve("http:g").toString()); |
| 89 | 104 |
| 90 // Additional tests (not from RFC 3986). | 105 // Additional tests (not from RFC 3986). |
| 91 Expect.stringEquals("http://a/b/g;p/h;s", | 106 Expect.stringEquals("http://a/b/g;p/h;s", |
| 92 base.resolve("../g;p/h;s").toString()); | 107 base.resolve("../g;p/h;s").toString()); |
| 108 |
| 109 // URI encode tests |
| 110 // Note: dart2js won't handle '\ud800\udc00' and frog |
| 111 // won't handle '\u{10000}'. So we cons this up synthetically... |
| 112 var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]); |
| 113 |
| 114 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
| 115 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
| 116 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
| 117 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
| 118 testEncodeDecode("\x7f", "%7F"); |
| 119 testEncodeDecode("\x80", "%C2%80"); |
| 120 testEncodeDecode("\u0800", "%E0%A0%80"); |
| 121 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$"); |
| 122 testEncodeDecode(s, "%F0%90%80%80"); |
| 123 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 124 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 125 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 126 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 127 testEncodeDecodeComponent("\x7f", "%7F"); |
| 128 testEncodeDecodeComponent("\x80", "%C2%80"); |
| 129 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); |
| 130 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); |
| 131 testEncodeDecodeComponent(s, "%F0%90%80%80"); |
| 93 } | 132 } |
| OLD | NEW |