| 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:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 testUri(String uri, bool isAbsolute) { | 10 testUri(String uri, bool isAbsolute) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 Expect.stringEquals(orig, d); | 23 Expect.stringEquals(orig, d); |
| 24 } | 24 } |
| 25 | 25 |
| 26 testEncodeDecodeComponent(String orig, String encoded) { | 26 testEncodeDecodeComponent(String orig, String encoded) { |
| 27 var e = Uri.encodeComponent(orig); | 27 var e = Uri.encodeComponent(orig); |
| 28 Expect.stringEquals(encoded, e); | 28 Expect.stringEquals(encoded, e); |
| 29 var d = Uri.decodeComponent(encoded); | 29 var d = Uri.decodeComponent(encoded); |
| 30 Expect.stringEquals(orig, d); | 30 Expect.stringEquals(orig, d); |
| 31 } | 31 } |
| 32 | 32 |
| 33 testEncodeDecodeQueryComponent(String orig, String encoded) { | 33 testEncodeDecodeQueryComponent(String orig, |
| 34 var e = Uri.encodeQueryComponent(orig); | 34 String encodedUTF8, |
| 35 Expect.stringEquals(encoded, e); | 35 String encodedLatin1, |
| 36 var d = Uri.decodeQueryComponent(encoded); | 36 String encodedAscii) { |
| 37 var e, d; |
| 38 e = Uri.encodeQueryComponent(orig); |
| 39 Expect.stringEquals(encodedUTF8, e); |
| 40 d = Uri.decodeQueryComponent(encodedUTF8); |
| 37 Expect.stringEquals(orig, d); | 41 Expect.stringEquals(orig, d); |
| 42 |
| 43 e = Uri.encodeQueryComponent(orig, encoding: UTF8); |
| 44 Expect.stringEquals(encodedUTF8, e); |
| 45 d = Uri.decodeQueryComponent(encodedUTF8, encoding: UTF8); |
| 46 Expect.stringEquals(orig, d); |
| 47 |
| 48 e = Uri.encodeQueryComponent(orig, encoding: LATIN1); |
| 49 Expect.stringEquals(encodedLatin1, e); |
| 50 d = Uri.decodeQueryComponent(encodedLatin1, encoding: LATIN1); |
| 51 Expect.stringEquals(orig, d); |
| 52 |
| 53 if (encodedAscii != null) { |
| 54 e = Uri.encodeQueryComponent(orig, encoding: ASCII); |
| 55 Expect.stringEquals(encodedAscii, e); |
| 56 d = Uri.decodeQueryComponent(encodedAscii, encoding: ASCII); |
| 57 Expect.stringEquals(orig, d); |
| 58 } else { |
| 59 Expect.throws(() => Uri.encodeQueryComponent(orig, encoding: ASCII), |
| 60 (e) => e is ArgumentError); |
| 61 } |
| 38 } | 62 } |
| 39 | 63 |
| 40 testUriPerRFCs(Uri base) { | 64 testUriPerRFCs(Uri base) { |
| 41 // From RFC 3986. | 65 // From RFC 3986. |
| 42 Expect.stringEquals("g:h", base.resolve("g:h").toString()); | 66 Expect.stringEquals("g:h", base.resolve("g:h").toString()); |
| 43 Expect.stringEquals("http://a/b/c/g", base.resolve("g").toString()); | 67 Expect.stringEquals("http://a/b/c/g", base.resolve("g").toString()); |
| 44 Expect.stringEquals("http://a/b/c/g", base.resolve("./g").toString()); | 68 Expect.stringEquals("http://a/b/c/g", base.resolve("./g").toString()); |
| 45 Expect.stringEquals("http://a/b/c/g/", base.resolve("g/").toString()); | 69 Expect.stringEquals("http://a/b/c/g/", base.resolve("g/").toString()); |
| 46 Expect.stringEquals("http://a/g", base.resolve("/g").toString()); | 70 Expect.stringEquals("http://a/g", base.resolve("/g").toString()); |
| 47 Expect.stringEquals("http://g", base.resolve("//g").toString()); | 71 Expect.stringEquals("http://g", base.resolve("//g").toString()); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 testEncodeDecodeComponent("A + B", "A%20%2B%20B"); | 246 testEncodeDecodeComponent("A + B", "A%20%2B%20B"); |
| 223 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 247 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 224 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 248 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 225 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 249 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 226 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 250 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 227 testEncodeDecodeComponent("\x7f", "%7F"); | 251 testEncodeDecodeComponent("\x7f", "%7F"); |
| 228 testEncodeDecodeComponent("\x80", "%C2%80"); | 252 testEncodeDecodeComponent("\x80", "%C2%80"); |
| 229 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); | 253 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); |
| 230 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); | 254 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); |
| 231 testEncodeDecodeComponent(s, "%F0%90%80%80"); | 255 testEncodeDecodeComponent(s, "%F0%90%80%80"); |
| 232 testEncodeDecodeQueryComponent("A + B", "A+%2B+B"); | 256 testEncodeDecodeQueryComponent("A + B", "A+%2B+B", "A+%2B+B", "A+%2B+B"); |
| 257 testEncodeDecodeQueryComponent( |
| 258 "æ ø å", "%C3%A6+%C3%B8+%C3%A5", "%E6+%F8+%E5", null); |
| 233 } | 259 } |
| OLD | NEW |