Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: tests/corelib/uri_test.dart

Issue 333163003: Add Uri.replace which creates a new Uri with the same fields as the original, but with some fields … (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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://@:/?#"),
372 Uri.parse("a://b@c:4/e/f?g#h"),
373 Uri.parse("$SCHEMECHAR://$USERINFOCHAR@$REGNAMECHAR:$DIGIT/$PCHAR/$PCHAR"
374 "?$QUERYCHAR#$QUERYCHAR"),
375 ];
376 for (var uri1 in uris) {
377 for (var uri2 in uris) {
378 if (identical(uri1, uri2)) continue;
379 var scheme = uri1.scheme;
380 var userInfo = uri1.hasAuthority ? uri1.userInfo : "";
381 var host = uri1.hasAuthority ? uri1.host : null;
382 var port = uri1.hasAuthority ? uri1.port : 0;
383 var path = uri1.path;
384 var query = uri1.hasQuery ? uri1.query : null;
385 var fragment = uri1.hasFragment ? uri1.fragment : null;
386
387 var tmp1 = uri1;
388 test() {
389 var tmp2 = new Uri(scheme: scheme, userInfo: userInfo, host: host,
390 port: port, path: path,
391 query: query == "" ? null : query,
392 queryParameters: query == "" ? {} : null,
393 fragment: fragment);
394 Expect.equals(tmp1, tmp2);
395 }
396
397 test();
398
399 scheme = uri2.scheme;
400 tmp1 = tmp1.replace(scheme: scheme);
401 test();
402
403 if (uri2.hasAuthority) {
404 userInfo = uri2.userInfo;
405 host = uri2.host;
406 port = uri2.port;
407 tmp1 = tmp1.replace(userInfo: userInfo, host: host, port: port);
408 test();
409 }
410
411 path = uri2.path;
412 tmp1 = tmp1.replace(path: path);
413 test();
414
415 if (uri2.hasQuery) {
416 query = uri2.query;
417 tmp1 = tmp1.replace(query: query);
418 test();
419 }
420
421 if (uri2.hasFragment) {
422 fragment = uri2.fragment;
423 tmp1 = tmp1.replace(fragment: fragment);
424 test();
425 }
426 }
427 }
428 }
429
368 main() { 430 main() {
369 testUri("http:", true); 431 testUri("http:", true);
370 testUri("file:///", true); 432 testUri("file:///", true);
371 testUri("file", false); 433 testUri("file", false);
372 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); 434 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true);
373 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", 435 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment",
374 false); 436 false);
375 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", 437 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment",
376 new Uri( 438 new Uri(
377 scheme: "http", 439 scheme: "http",
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 testEncodeDecodeComponent(nonAscii, nonAsciiEncoding); 584 testEncodeDecodeComponent(nonAscii, nonAsciiEncoding);
523 585
524 // Invalid URI - : and @ is swapped, port ("host") should be numeric. 586 // Invalid URI - : and @ is swapped, port ("host") should be numeric.
525 Expect.throws( 587 Expect.throws(
526 () => Uri.parse("file://user@password:host/path"), 588 () => Uri.parse("file://user@password:host/path"),
527 (e) => e is FormatException); 589 (e) => e is FormatException);
528 590
529 testValidCharacters(); 591 testValidCharacters();
530 testInvalidUrls(); 592 testInvalidUrls();
531 testNormalization(); 593 testNormalization();
594 testReplace();
532 } 595 }
533 596
534 String dump(Uri uri) { 597 String dump(Uri uri) {
535 return "URI: $uri\n" 598 return "URI: $uri\n"
536 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" 599 " Scheme: ${uri.scheme} #${uri.scheme.length}\n"
537 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" 600 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n"
538 " Host: ${uri.host} #${uri.host.length}\n" 601 " Host: ${uri.host} #${uri.host.length}\n"
539 " Port: ${uri.port}\n" 602 " Port: ${uri.port}\n"
540 " Path: ${uri.path} #${uri.path.length}\n" 603 " Path: ${uri.path} #${uri.path.length}\n"
541 " Query: ${uri.query} #${uri.query.length}\n" 604 " Query: ${uri.query} #${uri.query.length}\n"
542 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; 605 " Fragment: ${uri.fragment} #${uri.fragment.length}\n";
543 } 606 }
OLDNEW
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698