| 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 345 |
| 346 uri = new Uri(scheme: "file", path: "//y"); | 346 uri = new Uri(scheme: "file", path: "//y"); |
| 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 |
| 356 // Empty host/query/fragment ensures the delimiter is there. |
| 357 // Different from not being there. |
| 358 Expect.equals("scheme:/", Uri.parse("scheme:/").toString()); |
| 359 Expect.equals("scheme:/", |
| 360 new Uri(scheme: "scheme", path: "/").toString()); |
| 361 |
| 362 Expect.equals("scheme:///?#", Uri.parse("scheme:///?#").toString()); |
| 363 Expect.equals("scheme:///?#", |
| 364 new Uri(scheme: "scheme", host: "", path: "/", |
| 365 query: "", fragment: "").toString()); |
| 355 } | 366 } |
| 356 | 367 |
| 357 main() { | 368 main() { |
| 358 testUri("http:", true); | 369 testUri("http:", true); |
| 359 testUri("file://", true); | 370 testUri("file://", true); |
| 360 testUri("file", false); | 371 testUri("file", false); |
| 361 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); |
| 362 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", |
| 363 false); | 374 false); |
| 364 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", | 375 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", |
| 365 new Uri( | 376 new Uri( |
| 366 scheme: "http", | 377 scheme: "http", |
| 367 userInfo: "user", | 378 userInfo: "user", |
| 368 host: "example.com", | 379 host: "example.com", |
| 369 port: 80, | 380 port: 80, |
| 370 path: "/a/b/c", | 381 path: "/a/b/c", |
| 371 query: "query", | 382 query: "query", |
| 372 fragment: "fragment").toString()); | 383 fragment: "fragment").toString()); |
| 373 Expect.stringEquals("//null@null/a/b/c/", | 384 Expect.stringEquals("/a/b/c/", |
| 374 new Uri( | 385 new Uri( |
| 375 scheme: null, | 386 scheme: null, |
| 376 userInfo: null, | 387 userInfo: null, |
| 377 host: null, | 388 host: null, |
| 378 port: 0, | 389 port: 0, |
| 379 path: "/a/b/c/", | 390 path: "/a/b/c/", |
| 380 query: null, | 391 query: null, |
| 381 fragment: null).toString()); | 392 fragment: null).toString()); |
| 382 Expect.stringEquals("file://", Uri.parse("file:").toString()); | 393 Expect.stringEquals("file://", Uri.parse("file:").toString()); |
| 383 | 394 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 String dump(Uri uri) { | 534 String dump(Uri uri) { |
| 524 return "URI: $uri\n" | 535 return "URI: $uri\n" |
| 525 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 536 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
| 526 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 537 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
| 527 " Host: ${uri.host} #${uri.host.length}\n" | 538 " Host: ${uri.host} #${uri.host.length}\n" |
| 528 " Port: ${uri.port}\n" | 539 " Port: ${uri.port}\n" |
| 529 " Path: ${uri.path} #${uri.path.length}\n" | 540 " Path: ${uri.path} #${uri.path.length}\n" |
| 530 " Query: ${uri.query} #${uri.query.length}\n" | 541 " Query: ${uri.query} #${uri.query.length}\n" |
| 531 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 542 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
| 532 } | 543 } |
| OLD | NEW |