| 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 Expect.equals("//y", uri.path); | 347 Expect.equals("//y", uri.path); |
| 348 Expect.equals("file:////y", uri.toString()); | 348 Expect.equals("file:////y", uri.toString()); |
| 349 | 349 |
| 350 // File scheme noralizes to always showing authority, even if empty. | 350 // File scheme noralizes to always showing authority, even if empty. |
| 351 uri = new Uri(scheme: "file", path: "/y"); | 351 uri = new Uri(scheme: "file", path: "/y"); |
| 352 Expect.equals("file:///y", uri.toString()); | 352 Expect.equals("file:///y", uri.toString()); |
| 353 uri = new Uri(scheme: "file", path: "y"); | 353 uri = new Uri(scheme: "file", path: "y"); |
| 354 Expect.equals("file:///y", uri.toString()); | 354 Expect.equals("file:///y", uri.toString()); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void testReplace() { |
| 358 var uris = [ |
| 359 Uri.parse(""), |
| 360 Uri.parse("a://b@c:4/e/f?g#h"), |
| 361 Uri.parse("$SCHEMECHAR://$USERINFOCHAR@$REGNAMECHAR:$DIGIT/$PCHAR/$PCHAR" |
| 362 "?$QUERYCHAR#$QUERYCHAR"), |
| 363 ]; |
| 364 for (var uri1 in uris) { |
| 365 for (var uri2 in uris) { |
| 366 if (identical(uri1, uri2)) continue; |
| 367 var scheme = uri1.scheme; |
| 368 var userInfo = uri1.userInfo; |
| 369 var host = uri1.host; |
| 370 var port = uri1.port; |
| 371 var path = uri1.path; |
| 372 var query = uri1.query; |
| 373 var fragment = uri1.fragment; |
| 374 |
| 375 var tmp1 = uri1; |
| 376 test() { |
| 377 var tmp2 = new Uri(scheme: scheme, userInfo: userInfo, host: host, |
| 378 port: port, path: path, |
| 379 query: query, fragment: fragment); |
| 380 Expect.equals(tmp1, tmp2); |
| 381 } |
| 382 |
| 383 test(); |
| 384 |
| 385 scheme = uri2.scheme; |
| 386 tmp1 = tmp1.replace(scheme: scheme); |
| 387 test(); |
| 388 |
| 389 userInfo = uri2.userInfo; |
| 390 tmp1 = tmp1.replace(userInfo: userInfo); |
| 391 test(); |
| 392 |
| 393 host = uri2.host; |
| 394 tmp1 = tmp1.replace(host: host); |
| 395 test(); |
| 396 |
| 397 port = uri2.port; |
| 398 tmp1 = tmp1.replace(port: port); |
| 399 test(); |
| 400 |
| 401 path = uri2.path; |
| 402 tmp1 = tmp1.replace(path: path); |
| 403 test(); |
| 404 |
| 405 query = uri2.query; |
| 406 tmp1 = tmp1.replace(query: query); |
| 407 test(); |
| 408 |
| 409 fragment = uri2.fragment; |
| 410 tmp1 = tmp1.replace(fragment: fragment); |
| 411 test(); |
| 412 } |
| 413 } |
| 414 } |
| 415 |
| 357 main() { | 416 main() { |
| 358 testUri("http:", true); | 417 testUri("http:", true); |
| 359 testUri("file://", true); | 418 testUri("file://", true); |
| 360 testUri("file", false); | 419 testUri("file", false); |
| 361 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); | 420 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); |
| 362 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", | 421 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", |
| 363 false); | 422 false); |
| 364 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", | 423 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", |
| 365 new Uri( | 424 new Uri( |
| 366 scheme: "http", | 425 scheme: "http", |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 testEncodeDecodeComponent(nonAscii, nonAsciiEncoding); | 570 testEncodeDecodeComponent(nonAscii, nonAsciiEncoding); |
| 512 | 571 |
| 513 // Invalid URI - : and @ is swapped, port ("host") should be numeric. | 572 // Invalid URI - : and @ is swapped, port ("host") should be numeric. |
| 514 Expect.throws( | 573 Expect.throws( |
| 515 () => Uri.parse("file://user@password:host/path"), | 574 () => Uri.parse("file://user@password:host/path"), |
| 516 (e) => e is FormatException); | 575 (e) => e is FormatException); |
| 517 | 576 |
| 518 testValidCharacters(); | 577 testValidCharacters(); |
| 519 testInvalidUrls(); | 578 testInvalidUrls(); |
| 520 testNormalization(); | 579 testNormalization(); |
| 580 testReplace(); |
| 521 } | 581 } |
| 522 | 582 |
| 523 String dump(Uri uri) { | 583 String dump(Uri uri) { |
| 524 return "URI: $uri\n" | 584 return "URI: $uri\n" |
| 525 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 585 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
| 526 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 586 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
| 527 " Host: ${uri.host} #${uri.host.length}\n" | 587 " Host: ${uri.host} #${uri.host.length}\n" |
| 528 " Port: ${uri.port}\n" | 588 " Port: ${uri.port}\n" |
| 529 " Path: ${uri.path} #${uri.path.length}\n" | 589 " Path: ${uri.path} #${uri.path.length}\n" |
| 530 " Query: ${uri.query} #${uri.query.length}\n" | 590 " Query: ${uri.query} #${uri.query.length}\n" |
| 531 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 591 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
| 532 } | 592 } |
| OLD | NEW |