| 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/utf/utf.dart'); |
| 8 #import('../../lib/uri/uri.dart'); | 8 #import('../../lib/uri/uri.dart'); |
| 9 | 9 |
| 10 testUri(String uri, bool isAbsolute) { | 10 testUri(String uri, bool isAbsolute) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 main() { | 87 main() { |
| 88 testUri("http:", true); | 88 testUri("http:", true); |
| 89 testUri("file://", true); | 89 testUri("file://", true); |
| 90 testUri("file", false); | 90 testUri("file", false); |
| 91 testUri("http://user@example.com:80/fisk?query=89&hest=silas", true); | 91 testUri("http://user@example.com:80/fisk?query=89&hest=silas", true); |
| 92 testUri("http://user@example.com:80/fisk?query=89&hest=silas#fragment", | 92 testUri("http://user@example.com:80/fisk?query=89&hest=silas#fragment", |
| 93 false); | 93 false); |
| 94 Expect.stringEquals("http://user@example.com:80/a/b/c?query#fragment", | 94 Expect.stringEquals("http://user@example.com:80/a/b/c?query#fragment", |
| 95 const Uri.fromComponents( | 95 const Uri.fromComponents( |
| 96 "http", "user", "example.com", 80, "/a/b/c", | 96 scheme: "http", |
| 97 "query", "fragment").toString()); | 97 userInfo: "user", |
| 98 domain: "example.com", |
| 99 port: 80, |
| 100 path: "/a/b/c", |
| 101 query: "query", |
| 102 fragment: "fragment").toString()); |
| 98 Expect.stringEquals("null://null@null/a/b/c/?null#null", | 103 Expect.stringEquals("null://null@null/a/b/c/?null#null", |
| 99 const Uri.fromComponents( | 104 const Uri.fromComponents( |
| 100 null, null, null, 0, "/a/b/c/", | 105 scheme: null, |
| 101 null, null).toString()); | 106 userInfo: null, |
| 107 domain: null, |
| 108 port: 0, |
| 109 path: "/a/b/c/", |
| 110 query: null, |
| 111 fragment: null).toString()); |
| 102 Expect.stringEquals("file://", new Uri.fromString("file:").toString()); | 112 Expect.stringEquals("file://", new Uri.fromString("file:").toString()); |
| 103 Expect.stringEquals("file://", new Uri("file:").toString()); | 113 Expect.stringEquals("file://", new Uri("file:").toString()); |
| 104 Expect.stringEquals("/a/g", removeDotSegments("/a/b/c/./../../g")); | 114 Expect.stringEquals("/a/g", removeDotSegments("/a/b/c/./../../g")); |
| 105 Expect.stringEquals("mid/6", removeDotSegments("mid/content=5/../6")); | 115 Expect.stringEquals("mid/6", removeDotSegments("mid/content=5/../6")); |
| 106 Expect.stringEquals("a/b/e", removeDotSegments("a/b/c/d/../../e")); | 116 Expect.stringEquals("a/b/e", removeDotSegments("a/b/c/d/../../e")); |
| 107 Expect.stringEquals("a/b/e", removeDotSegments("../a/b/c/d/../../e")); | 117 Expect.stringEquals("a/b/e", removeDotSegments("../a/b/c/d/../../e")); |
| 108 Expect.stringEquals("a/b/e", removeDotSegments("./a/b/c/d/../../e")); | 118 Expect.stringEquals("a/b/e", removeDotSegments("./a/b/c/d/../../e")); |
| 109 Expect.stringEquals("a/b/e", removeDotSegments("../a/b/./c/d/../../e")); | 119 Expect.stringEquals("a/b/e", removeDotSegments("../a/b/./c/d/../../e")); |
| 110 Expect.stringEquals("a/b/e", removeDotSegments("./a/b/./c/d/../../e")); | 120 Expect.stringEquals("a/b/e", removeDotSegments("./a/b/./c/d/../../e")); |
| 111 Expect.stringEquals("a/b/e/", removeDotSegments("./a/b/./c/d/../../e/.")); | 121 Expect.stringEquals("a/b/e/", removeDotSegments("./a/b/./c/d/../../e/.")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 128 "http://example.com:1234", | 138 "http://example.com:1234", |
| 129 new Uri.fromString("http://example.com:1234/a/b/c").origin); | 139 new Uri.fromString("http://example.com:1234/a/b/c").origin); |
| 130 Expect.stringEquals( | 140 Expect.stringEquals( |
| 131 "https://example.com:1234", | 141 "https://example.com:1234", |
| 132 new Uri.fromString("https://example.com:1234/a/b/c").origin); | 142 new Uri.fromString("https://example.com:1234/a/b/c").origin); |
| 133 Expect.throws( | 143 Expect.throws( |
| 134 () => new Uri.fromString("http:").origin, | 144 () => new Uri.fromString("http:").origin, |
| 135 (e) { return e is IllegalArgumentException; }, | 145 (e) { return e is IllegalArgumentException; }, |
| 136 "origin for uri with empty domain should fail"); | 146 "origin for uri with empty domain should fail"); |
| 137 Expect.throws( | 147 Expect.throws( |
| 138 () => const Uri.fromComponents("http", null, "", 80, "/a/b/c", | 148 () => const Uri.fromComponents( |
| 139 "query", "fragment").origin, | 149 scheme: "http", |
| 150 userInfo: null, |
| 151 domain: "", |
| 152 port: 80, |
| 153 path: "/a/b/c", |
| 154 query: "query", |
| 155 fragment: "fragment").origin, |
| 140 (e) { return e is IllegalArgumentException; }, | 156 (e) { return e is IllegalArgumentException; }, |
| 141 "origin for uri with empty domain should fail"); | 157 "origin for uri with empty domain should fail"); |
| 142 Expect.throws( | 158 Expect.throws( |
| 143 () => const Uri.fromComponents(null, null, "", 80, "/a/b/c", | 159 () => const Uri.fromComponents( |
| 144 "query", "fragment").origin, | 160 scheme: null, |
| 161 userInfo: null, |
| 162 domain: "", |
| 163 port: 80, |
| 164 path: "/a/b/c", |
| 165 query: "query", |
| 166 fragment: "fragment").origin, |
| 145 (e) { return e is IllegalArgumentException; }, | 167 (e) { return e is IllegalArgumentException; }, |
| 146 "origin for uri with empty scheme should fail"); | 168 "origin for uri with empty scheme should fail"); |
| 147 Expect.throws( | 169 Expect.throws( |
| 148 () => const Uri.fromComponents("http", null, null, 80, "/a/b/c", | 170 () => const Uri.fromComponents( |
| 149 "query", "fragment").origin, | 171 scheme: "http", |
| 172 userInfo: null, |
| 173 domain: null, |
| 174 port: 80, |
| 175 path: "/a/b/c", |
| 176 query: "query", |
| 177 fragment: "fragment").origin, |
| 150 (e) { return e is IllegalArgumentException; }, | 178 (e) { return e is IllegalArgumentException; }, |
| 151 "origin for uri with empty domain should fail"); | 179 "origin for uri with empty domain should fail"); |
| 152 Expect.throws( | 180 Expect.throws( |
| 153 () => new Uri.fromString("http://:80").origin, | 181 () => new Uri.fromString("http://:80").origin, |
| 154 (e) { return e is IllegalArgumentException; }, | 182 (e) { return e is IllegalArgumentException; }, |
| 155 "origin for uri with empty domain should fail"); | 183 "origin for uri with empty domain should fail"); |
| 156 Expect.throws( | 184 Expect.throws( |
| 157 () => new Uri.fromString("file://localhost/test.txt").origin, | 185 () => new Uri.fromString("file://localhost/test.txt").origin, |
| 158 (e) { return e is IllegalArgumentException; }, | 186 (e) { return e is IllegalArgumentException; }, |
| 159 "origin for non-http/https uri should fail"); | 187 "origin for non-http/https uri should fail"); |
| 160 | 188 |
| 161 // URI encode tests | 189 // URI encode tests |
| 162 // Note: dart2js won't handle '\ud800\udc00' and frog | 190 // Note: dart2js won't handle '\ud800\udc00' and frog |
| 163 // won't handle '\u{10000}'. So we cons this up synthetically... | 191 // won't handle '\u{10000}'. So we cons this up synthetically... |
| 164 var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]); | 192 var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]); |
| 165 | 193 |
| 166 testEncodeDecode("\uFFFE", "%EF%BF%BE"); | 194 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
| 167 testEncodeDecode("\uFFFF", "%EF%BF%BF"); | 195 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
| 168 testEncodeDecode("\uFFFE", "%EF%BF%BE"); | 196 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
| 169 testEncodeDecode("\uFFFF", "%EF%BF%BF"); | 197 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
| 170 testEncodeDecode("\x7f", "%7F"); | 198 testEncodeDecode("\x7f", "%7F"); |
| 171 testEncodeDecode("\x80", "%C2%80"); | 199 testEncodeDecode("\x80", "%C2%80"); |
| 172 testEncodeDecode("\u0800", "%E0%A0%80"); | 200 testEncodeDecode("\u0800", "%E0%A0%80"); |
| 173 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$"); | 201 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$"); |
| 174 testEncodeDecode(s, "%F0%90%80%80"); | 202 testEncodeDecode(s, "%F0%90%80%80"); |
| 175 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 203 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 176 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 204 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 177 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 205 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 178 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 206 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 179 testEncodeDecodeComponent("\x7f", "%7F"); | 207 testEncodeDecodeComponent("\x7f", "%7F"); |
| 180 testEncodeDecodeComponent("\x80", "%C2%80"); | 208 testEncodeDecodeComponent("\x80", "%C2%80"); |
| 181 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); | 209 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); |
| 182 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); | 210 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); |
| 183 testEncodeDecodeComponent(s, "%F0%90%80%80"); | 211 testEncodeDecodeComponent(s, "%F0%90%80%80"); |
| 184 } | 212 } |
| OLD | NEW |