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