| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 Expect.equals("scheme:/", Uri.parse("scheme:/").toString()); | 358 Expect.equals("scheme:/", Uri.parse("scheme:/").toString()); |
| 359 Expect.equals("scheme:/", | 359 Expect.equals("scheme:/", |
| 360 new Uri(scheme: "scheme", path: "/").toString()); | 360 new Uri(scheme: "scheme", path: "/").toString()); |
| 361 | 361 |
| 362 Expect.equals("scheme:///?#", Uri.parse("scheme:///?#").toString()); | 362 Expect.equals("scheme:///?#", Uri.parse("scheme:///?#").toString()); |
| 363 Expect.equals("scheme:///#", | 363 Expect.equals("scheme:///#", |
| 364 new Uri(scheme: "scheme", host: "", path: "/", | 364 new Uri(scheme: "scheme", host: "", path: "/", |
| 365 query: "", fragment: "").toString()); | 365 query: "", fragment: "").toString()); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void testReplace() { | |
| 369 var uris = [ | |
| 370 Uri.parse(""), | |
| 371 Uri.parse("a://b@c:4/e/f?g#h"), | |
| 372 Uri.parse("$SCHEMECHAR://$USERINFOCHAR@$REGNAMECHAR:$DIGIT/$PCHAR/$PCHAR" | |
| 373 "?$QUERYCHAR#$QUERYCHAR"), | |
| 374 ]; | |
| 375 for (var uri1 in uris) { | |
| 376 for (var uri2 in uris) { | |
| 377 if (identical(uri1, uri2)) continue; | |
| 378 var scheme = uri1.scheme; | |
| 379 var userInfo = uri1.userInfo; | |
| 380 var host = uri1.host; | |
| 381 var port = uri1.port; | |
| 382 var path = uri1.path; | |
| 383 var query = uri1.query; | |
| 384 var fragment = uri1.fragment; | |
| 385 | |
| 386 var tmp1 = uri1; | |
| 387 test() { | |
| 388 var tmp2 = new Uri(scheme: scheme, userInfo: userInfo, host: host, | |
| 389 port: port, path: path, | |
| 390 query: query, fragment: fragment); | |
| 391 Expect.equals(tmp1, tmp2); | |
| 392 } | |
| 393 | |
| 394 test(); | |
| 395 | |
| 396 scheme = uri2.scheme; | |
| 397 tmp1 = tmp1.replace(scheme: scheme); | |
| 398 test(); | |
| 399 | |
| 400 userInfo = uri2.userInfo; | |
| 401 tmp1 = tmp1.replace(userInfo: userInfo); | |
| 402 test(); | |
| 403 | |
| 404 host = uri2.host; | |
| 405 tmp1 = tmp1.replace(host: host); | |
| 406 test(); | |
| 407 | |
| 408 port = uri2.port; | |
| 409 tmp1 = tmp1.replace(port: port); | |
| 410 test(); | |
| 411 | |
| 412 path = uri2.path; | |
| 413 tmp1 = tmp1.replace(path: path); | |
| 414 test(); | |
| 415 | |
| 416 query = uri2.query; | |
| 417 tmp1 = tmp1.replace(query: query); | |
| 418 test(); | |
| 419 | |
| 420 fragment = uri2.fragment; | |
| 421 tmp1 = tmp1.replace(fragment: fragment); | |
| 422 test(); | |
| 423 } | |
| 424 } | |
| 425 } | |
| 426 | |
| 427 main() { | 368 main() { |
| 428 testUri("http:", true); | 369 testUri("http:", true); |
| 429 testUri("file:///", true); | 370 testUri("file:///", true); |
| 430 testUri("file", false); | 371 testUri("file", false); |
| 431 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); | 372 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); |
| 432 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", | 373 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", |
| 433 false); | 374 false); |
| 434 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", | 375 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", |
| 435 new Uri( | 376 new Uri( |
| 436 scheme: "http", | 377 scheme: "http", |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 testEncodeDecodeComponent(nonAscii, nonAsciiEncoding); | 522 testEncodeDecodeComponent(nonAscii, nonAsciiEncoding); |
| 582 | 523 |
| 583 // Invalid URI - : and @ is swapped, port ("host") should be numeric. | 524 // Invalid URI - : and @ is swapped, port ("host") should be numeric. |
| 584 Expect.throws( | 525 Expect.throws( |
| 585 () => Uri.parse("file://user@password:host/path"), | 526 () => Uri.parse("file://user@password:host/path"), |
| 586 (e) => e is FormatException); | 527 (e) => e is FormatException); |
| 587 | 528 |
| 588 testValidCharacters(); | 529 testValidCharacters(); |
| 589 testInvalidUrls(); | 530 testInvalidUrls(); |
| 590 testNormalization(); | 531 testNormalization(); |
| 591 testReplace(); | |
| 592 } | 532 } |
| 593 | 533 |
| 594 String dump(Uri uri) { | 534 String dump(Uri uri) { |
| 595 return "URI: $uri\n" | 535 return "URI: $uri\n" |
| 596 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 536 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
| 597 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 537 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
| 598 " Host: ${uri.host} #${uri.host.length}\n" | 538 " Host: ${uri.host} #${uri.host.length}\n" |
| 599 " Port: ${uri.port}\n" | 539 " Port: ${uri.port}\n" |
| 600 " Path: ${uri.path} #${uri.path.length}\n" | 540 " Path: ${uri.path} #${uri.path.length}\n" |
| 601 " Query: ${uri.query} #${uri.query.length}\n" | 541 " Query: ${uri.query} #${uri.query.length}\n" |
| 602 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 542 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
| 603 } | 543 } |
| OLD | NEW |