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) { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 if (identical(uri1, uri2)) continue; | 400 if (identical(uri1, uri2)) continue; |
401 var scheme = uri1.scheme; | 401 var scheme = uri1.scheme; |
402 var userInfo = uri1.hasAuthority ? uri1.userInfo : ""; | 402 var userInfo = uri1.hasAuthority ? uri1.userInfo : ""; |
403 var host = uri1.hasAuthority ? uri1.host : null; | 403 var host = uri1.hasAuthority ? uri1.host : null; |
404 var port = uri1.hasAuthority ? uri1.port : 0; | 404 var port = uri1.hasAuthority ? uri1.port : 0; |
405 var path = uri1.path; | 405 var path = uri1.path; |
406 var query = uri1.hasQuery ? uri1.query : null; | 406 var query = uri1.hasQuery ? uri1.query : null; |
407 var fragment = uri1.hasFragment ? uri1.fragment : null; | 407 var fragment = uri1.hasFragment ? uri1.fragment : null; |
408 | 408 |
409 var tmp1 = uri1; | 409 var tmp1 = uri1; |
410 test() { | 410 |
| 411 void test() { |
411 var tmp2 = new Uri(scheme: scheme, userInfo: userInfo, host: host, | 412 var tmp2 = new Uri(scheme: scheme, userInfo: userInfo, host: host, |
412 port: port, path: path, | 413 port: port, path: path, |
413 query: query == "" ? null : query, | 414 query: query == "" ? null : query, |
414 queryParameters: query == "" ? {} : null, | 415 queryParameters: query == "" ? {} : null, |
415 fragment: fragment); | 416 fragment: fragment); |
416 Expect.equals(tmp1, tmp2); | 417 Expect.equals(tmp1, tmp2); |
417 } | 418 } |
418 | 419 |
419 test(); | 420 test(); |
420 | 421 |
(...skipping 24 matching lines...) Expand all Loading... |
445 tmp1 = tmp1.replace(fragment: fragment); | 446 tmp1 = tmp1.replace(fragment: fragment); |
446 test(); | 447 test(); |
447 } | 448 } |
448 } | 449 } |
449 } | 450 } |
450 | 451 |
451 // Regression test, http://dartbug.com/20814 | 452 // Regression test, http://dartbug.com/20814 |
452 var uri = Uri.parse("/no-authorty/"); | 453 var uri = Uri.parse("/no-authorty/"); |
453 uri = uri.replace(fragment: "fragment"); | 454 uri = uri.replace(fragment: "fragment"); |
454 Expect.isFalse(uri.hasAuthority); | 455 Expect.isFalse(uri.hasAuthority); |
| 456 |
| 457 uri = new Uri(scheme: "foo", path: "bar"); |
| 458 uri = uri.replace( |
| 459 queryParameters: {"x": ["42", "37"], "y": ["43", "38"]}); |
| 460 var params = uri.queryParametersAll; |
| 461 Expect.equals(2, params.length); |
| 462 Expect.listEquals(["42", "37"], params["x"]); |
| 463 Expect.listEquals(["43", "38"], params["y"]); |
455 } | 464 } |
456 | 465 |
457 main() { | 466 main() { |
458 testUri("http:", true); | 467 testUri("http:", true); |
459 testUri("file:///", true); | 468 testUri("file:///", true); |
460 testUri("file", false); | 469 testUri("file", false); |
461 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); | 470 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); |
462 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", | 471 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", |
463 false); | 472 false); |
464 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", | 473 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 String dump(Uri uri) { | 629 String dump(Uri uri) { |
621 return "URI: $uri\n" | 630 return "URI: $uri\n" |
622 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 631 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
623 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 632 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
624 " Host: ${uri.host} #${uri.host.length}\n" | 633 " Host: ${uri.host} #${uri.host.length}\n" |
625 " Port: ${uri.port}\n" | 634 " Port: ${uri.port}\n" |
626 " Path: ${uri.path} #${uri.path.length}\n" | 635 " Path: ${uri.path} #${uri.path.length}\n" |
627 " Query: ${uri.query} #${uri.query.length}\n" | 636 " Query: ${uri.query} #${uri.query.length}\n" |
628 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 637 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
629 } | 638 } |
OLD | NEW |