| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 | |
| 8 void testUriCombi() { | 7 void testUriCombi() { |
| 9 var schemes = ["", "file", "ws", "ftp"]; | 8 var schemes = ["", "file", "ws", "ftp"]; |
| 10 var fragments = ["", "#", "#f", "#fragment", "#l:?/"]; | 9 var fragments = ["", "#", "#f", "#fragment", "#l:?/"]; |
| 11 var queries = ["", "?", "?q", "?query", "?q:/"]; | 10 var queries = ["", "?", "?q", "?query", "?q:/"]; |
| 12 var paths = ["/", "/x", "/x/y", "/x/y/", "/x:y", "x", "x/y", "x/y/"]; | 11 var paths = ["/", "/x", "/x/y", "/x/y/", "/x:y", "x", "x/y", "x/y/"]; |
| 13 var userInfos = ["", "x", "xxx", "x:4", "xxx:444", "x:4:x"]; | 12 var userInfos = ["", "x", "xxx", "x:4", "xxx:444", "x:4:x"]; |
| 14 var hosts = ["", "h", "hhh", "h:4", "hhh:444", "[::1.2.3.4]"]; | 13 var hosts = ["", "h", "hhh", "h:4", "hhh:444", "[::1.2.3.4]"]; |
| 15 | 14 |
| 16 void check(uriString, scheme, fragment, query, path, user, host) { | 15 void check(uriString, scheme, fragment, query, path, user, host) { |
| 17 for (var uri in [Uri.parse(uriString), | 16 for (var uri in [ |
| 18 Uri.parse(">\u{10000}>$uriString<\u{10000}<", | 17 Uri.parse(uriString), |
| 19 4, uriString.length + 4), | 18 Uri.parse(">\u{10000}>$uriString<\u{10000}<", 4, uriString.length + 4), |
| 20 Uri.parse("http://example.com/$uriString#?:/[]\"", | 19 Uri.parse( |
| 21 19, uriString.length + 19), | 20 "http://example.com/$uriString#?:/[]\"", 19, uriString.length + 19), |
| 22 Uri.parse(uriString * 3, | 21 Uri.parse(uriString * 3, uriString.length, uriString.length * 2) |
| 23 uriString.length, uriString.length * 2)]) { | 22 ]) { |
| 24 String name = "$uriString -> $uri"; | 23 String name = "$uriString -> $uri"; |
| 25 Expect.equals(scheme, uri.scheme, name); | 24 Expect.equals(scheme, uri.scheme, name); |
| 26 var uriFragment = uri.fragment; | 25 var uriFragment = uri.fragment; |
| 27 if (fragment.startsWith('#')) uriFragment = "#$uriFragment"; | 26 if (fragment.startsWith('#')) uriFragment = "#$uriFragment"; |
| 28 Expect.equals(fragment, uriFragment, name); | 27 Expect.equals(fragment, uriFragment, name); |
| 29 var uriQuery = uri.query; | 28 var uriQuery = uri.query; |
| 30 if (query.startsWith('?')) uriQuery = "?$uriQuery"; | 29 if (query.startsWith('?')) uriQuery = "?$uriQuery"; |
| 31 Expect.equals(query, uriQuery, name); | 30 Expect.equals(query, uriQuery, name); |
| 32 Expect.equals(path, uri.path, name); | 31 Expect.equals(path, uri.path, name); |
| 33 Expect.equals(user, uri.userInfo, name); | 32 Expect.equals(user, uri.userInfo, name); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 for (var path in paths) { | 43 for (var path in paths) { |
| 45 // File scheme URIs always get a leading slash. | 44 // File scheme URIs always get a leading slash. |
| 46 if (scheme == "file" && !path.startsWith('/')) continue; | 45 if (scheme == "file" && !path.startsWith('/')) continue; |
| 47 for (var user in userInfos) { | 46 for (var user in userInfos) { |
| 48 for (var host in hosts) { | 47 for (var host in hosts) { |
| 49 var auth = host; | 48 var auth = host; |
| 50 var s = scheme; | 49 var s = scheme; |
| 51 if (user.isNotEmpty) auth = "$user@$auth"; | 50 if (user.isNotEmpty) auth = "$user@$auth"; |
| 52 if (auth.isNotEmpty) auth = "//$auth"; | 51 if (auth.isNotEmpty) auth = "//$auth"; |
| 53 if (auth.isNotEmpty && !path.startsWith('/')) continue; | 52 if (auth.isNotEmpty && !path.startsWith('/')) continue; |
| 54 check("$scheme${scheme.isEmpty ? "" : ":"}" | 53 check( |
| 55 "$auth$path$query$fragment", | 54 "$scheme${scheme.isEmpty ? "" : ":"}" |
| 56 scheme, | 55 "$auth$path$query$fragment", |
| 57 fragment, | 56 scheme, |
| 58 query, | 57 fragment, |
| 59 path, | 58 query, |
| 60 user, | 59 path, |
| 61 host); | 60 user, |
| 61 host); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 void main() { | 70 void main() { |
| 71 testUriCombi(); | 71 testUriCombi(); |
| 72 } | 72 } |
| OLD | NEW |