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 "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import 'dart:utf'; | 8 import 'dart:convert'; |
9 | 9 |
10 testUri(String uri, bool isAbsolute) { | 10 testUri(String uri, bool isAbsolute) { |
11 Expect.equals(isAbsolute, Uri.parse(uri).isAbsolute); | 11 Expect.equals(isAbsolute, Uri.parse(uri).isAbsolute); |
12 Expect.stringEquals(uri, Uri.parse(uri).toString()); | 12 Expect.stringEquals(uri, Uri.parse(uri).toString()); |
13 | 13 |
14 // Test equals and hashCode members. | 14 // Test equals and hashCode members. |
15 Expect.equals(Uri.parse(uri), Uri.parse(uri)); | 15 Expect.equals(Uri.parse(uri), Uri.parse(uri)); |
16 Expect.equals(Uri.parse(uri).hashCode, Uri.parse(uri).hashCode); | 16 Expect.equals(Uri.parse(uri).hashCode, Uri.parse(uri).hashCode); |
17 } | 17 } |
18 | 18 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 () => Uri.parse("http://:80").origin, | 198 () => Uri.parse("http://:80").origin, |
199 (e) { return e is StateError; }, | 199 (e) { return e is StateError; }, |
200 "origin for uri with empty host should fail"); | 200 "origin for uri with empty host should fail"); |
201 Expect.throws( | 201 Expect.throws( |
202 () => Uri.parse("file://localhost/test.txt").origin, | 202 () => Uri.parse("file://localhost/test.txt").origin, |
203 (e) { return e is StateError; }, | 203 (e) { return e is StateError; }, |
204 "origin for non-http/https uri should fail"); | 204 "origin for non-http/https uri should fail"); |
205 | 205 |
206 // URI encode tests | 206 // URI encode tests |
207 // Create a string with code point 0x10000 encoded as a surrogate pair. | 207 // Create a string with code point 0x10000 encoded as a surrogate pair. |
208 var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]); | 208 var s = UTF8.decode([0xf0, 0x90, 0x80, 0x80]); |
Lasse Reichstein Nielsen
2013/08/27 09:22:42
Why not just "\u{10000}"? This is not a test if UT
floitsch
2013/08/27 09:33:58
It tests just below that these two strings are act
| |
209 | 209 |
210 Expect.stringEquals("\u{10000}", s); | 210 Expect.stringEquals("\u{10000}", s); |
211 | 211 |
212 testEncodeDecode("A + B", "A%20%2B%20B"); | 212 testEncodeDecode("A + B", "A%20%2B%20B"); |
213 testEncodeDecode("\uFFFE", "%EF%BF%BE"); | 213 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
214 testEncodeDecode("\uFFFF", "%EF%BF%BF"); | 214 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
215 testEncodeDecode("\uFFFE", "%EF%BF%BE"); | 215 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
216 testEncodeDecode("\uFFFF", "%EF%BF%BF"); | 216 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
217 testEncodeDecode("\x7f", "%7F"); | 217 testEncodeDecode("\x7f", "%7F"); |
218 testEncodeDecode("\x80", "%C2%80"); | 218 testEncodeDecode("\x80", "%C2%80"); |
219 testEncodeDecode("\u0800", "%E0%A0%80"); | 219 testEncodeDecode("\u0800", "%E0%A0%80"); |
220 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=%2B\$"); | 220 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=%2B\$"); |
221 testEncodeDecode(s, "%F0%90%80%80"); | 221 testEncodeDecode(s, "%F0%90%80%80"); |
222 testEncodeDecodeComponent("A + B", "A%20%2B%20B"); | 222 testEncodeDecodeComponent("A + B", "A%20%2B%20B"); |
223 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 223 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
224 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 224 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
225 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 225 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
226 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 226 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
227 testEncodeDecodeComponent("\x7f", "%7F"); | 227 testEncodeDecodeComponent("\x7f", "%7F"); |
228 testEncodeDecodeComponent("\x80", "%C2%80"); | 228 testEncodeDecodeComponent("\x80", "%C2%80"); |
229 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); | 229 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); |
230 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); | 230 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); |
231 testEncodeDecodeComponent(s, "%F0%90%80%80"); | 231 testEncodeDecodeComponent(s, "%F0%90%80%80"); |
232 testEncodeDecodeQueryComponent("A + B", "A+%2B+B"); | 232 testEncodeDecodeQueryComponent("A + B", "A+%2B+B"); |
233 } | 233 } |
OLD | NEW |