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 uriText, bool isAbsolute) { | 10 testUri(String uriText, bool isAbsolute) { |
11 var uri = Uri.parse(uriText); | 11 var uri = Uri.parse(uriText); |
12 | 12 |
13 // Test that parsing a substring works the same as parsing the string. | 13 // Test that parsing a substring works the same as parsing the string. |
14 String wrapper = "://@[]:/%?#"; | 14 String wrapper = "://@[]:/%?#"; |
15 var embeddedUri = Uri.parse( | 15 var embeddedUri = Uri.parse( |
16 "$wrapper$uri$wrapper", wrapper.length, uriText.length + wrapper.length); | 16 "$wrapper$uri$wrapper", wrapper.length, uriText.length + wrapper.length); |
17 | 17 |
18 Expect.equals(uri, embeddedUri); | 18 Expect.equals(uri, embeddedUri); |
19 Expect.equals(isAbsolute, uri.isAbsolute); | 19 Expect.equals(isAbsolute, uri.isAbsolute); |
20 Expect.stringEquals(uriText, uri.toString()); | 20 Expect.stringEquals(uriText, uri.toString()); |
21 | 21 |
22 // Test equals and hashCode members. | 22 // Test equals and hashCode members. |
23 var uri2 = Uri.parse(uriText); | 23 var uri2 = Uri.parse(uriText); |
24 Expect.equals(uri, uri2); | 24 Expect.equals(uri, uri2); |
25 Expect.equals(uri.hashCode, uri2.hashCode); | 25 Expect.equals(uri.hashCode, uri2.hashCode); |
26 | 26 |
27 | |
Harry Terkelsen
2016/07/18 22:48:12
nit: delete
keertip
2016/07/18 23:29:32
Done.
| |
27 // Test that removeFragment doesn't change anything else. | 28 // Test that removeFragment doesn't change anything else. |
28 if (uri.hasFragment) { | 29 if (uri.hasFragment) { |
29 Expect.equals(Uri.parse(uriText.substring(0, uriText.indexOf('#'))), | 30 Expect.equals(Uri.parse(uriText.substring(0, uriText.indexOf('#'))), |
30 uri.removeFragment()); | 31 uri.removeFragment()); |
31 } else { | 32 } else { |
32 Expect.equals(uri, | 33 Expect.equals(uri, |
33 Uri.parse(uriText + "#fragment").removeFragment()); | 34 Uri.parse(uriText + "#fragment").removeFragment()); |
34 } | 35 } |
36 | |
37 // Test uri.replace on uri with fragment | |
38 uri = Uri.parse('http://hello.com/fake#fragment'); | |
39 uri = uri.replace(path: "D/E/E"); | |
40 Expect.stringEquals('http://hello.com/D/E/E#fragment', uri.toString()); | |
35 } | 41 } |
36 | 42 |
37 testEncodeDecode(String orig, String encoded) { | 43 testEncodeDecode(String orig, String encoded) { |
38 var e = Uri.encodeFull(orig); | 44 var e = Uri.encodeFull(orig); |
39 Expect.stringEquals(encoded, e); | 45 Expect.stringEquals(encoded, e); |
40 var d = Uri.decodeFull(encoded); | 46 var d = Uri.decodeFull(encoded); |
41 Expect.stringEquals(orig, d); | 47 Expect.stringEquals(orig, d); |
42 } | 48 } |
43 | 49 |
44 testEncodeDecodeComponent(String orig, String encoded) { | 50 testEncodeDecodeComponent(String orig, String encoded) { |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 String dump(Uri uri) { | 864 String dump(Uri uri) { |
859 return "URI: $uri\n" | 865 return "URI: $uri\n" |
860 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 866 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
861 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 867 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
862 " Host: ${uri.host} #${uri.host.length}\n" | 868 " Host: ${uri.host} #${uri.host.length}\n" |
863 " Port: ${uri.port}\n" | 869 " Port: ${uri.port}\n" |
864 " Path: ${uri.path} #${uri.path.length}\n" | 870 " Path: ${uri.path} #${uri.path.length}\n" |
865 " Query: ${uri.query} #${uri.query.length}\n" | 871 " Query: ${uri.query} #${uri.query.length}\n" |
866 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 872 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
867 } | 873 } |
OLD | NEW |