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

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

Issue 2664453003: Add Uri.isScheme test function. (Closed)
Patch Set: Address comment. Created 3 years, 10 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
« 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 uriText, bool isAbsolute) { 10 testUri(String uriText, bool isAbsolute) {
(...skipping 15 matching lines...) Expand all
26 26
27 // Test that removeFragment doesn't change anything else. 27 // Test that removeFragment doesn't change anything else.
28 if (uri.hasFragment) { 28 if (uri.hasFragment) {
29 Expect.equals(Uri.parse(uriText.substring(0, uriText.indexOf('#'))), 29 Expect.equals(Uri.parse(uriText.substring(0, uriText.indexOf('#'))),
30 uri.removeFragment()); 30 uri.removeFragment());
31 } else { 31 } else {
32 Expect.equals(uri, 32 Expect.equals(uri,
33 Uri.parse(uriText + "#fragment").removeFragment()); 33 Uri.parse(uriText + "#fragment").removeFragment());
34 } 34 }
35 35
36 // Test uri.replace on uri with fragment 36 Expect.isTrue(uri.isScheme(uri.scheme));
37 uri = Uri.parse('http://hello.com/fake#fragment'); 37 Expect.isTrue(uri.isScheme(uri.scheme.toLowerCase()));
38 uri = uri.replace(path: "D/E/E"); 38 Expect.isTrue(uri.isScheme(uri.scheme.toUpperCase()));
39 Expect.stringEquals('http://hello.com/D/E/E#fragment', uri.toString()); 39 if (uri.hasScheme) {
40 // Capitalize
41 Expect.isTrue(uri.isScheme(
42 uri.scheme[0].toUpperCase()+uri.scheme.substring(1)));
43 Expect.isFalse(uri.isScheme(
44 uri.scheme.substring(0, uri.scheme.length - 1)));
45 Expect.isFalse(uri.isScheme(uri.scheme + ":"));
46 Expect.isFalse(uri.isScheme(uri.scheme + "\x00"));
47 } else {
48 Expect.isTrue(uri.isScheme(null));
49 Expect.isFalse(uri.isScheme(":"));
50 }
40 } 51 }
41 52
42 testEncodeDecode(String orig, String encoded) { 53 testEncodeDecode(String orig, String encoded) {
43 var e = Uri.encodeFull(orig); 54 var e = Uri.encodeFull(orig);
44 Expect.stringEquals(encoded, e); 55 Expect.stringEquals(encoded, e);
45 var d = Uri.decodeFull(encoded); 56 var d = Uri.decodeFull(encoded);
46 Expect.stringEquals(orig, d); 57 Expect.stringEquals(orig, d);
47 } 58 }
48 59
49 testEncodeDecodeComponent(String orig, String encoded) { 60 testEncodeDecodeComponent(String orig, String encoded) {
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 Expect.equals(2, params.length); 757 Expect.equals(2, params.length);
747 Expect.listEquals(["42", "37"], params["x"]); 758 Expect.listEquals(["42", "37"], params["x"]);
748 Expect.listEquals(["43", "38"], params["y"]); 759 Expect.listEquals(["43", "38"], params["y"]);
749 760
750 // Test replacing with empty strings. 761 // Test replacing with empty strings.
751 uri = Uri.parse("s://a:1/b/c?d#e"); 762 uri = Uri.parse("s://a:1/b/c?d#e");
752 Expect.equals("s://a:1/b/c?d#", uri.replace(fragment: "").toString()); 763 Expect.equals("s://a:1/b/c?d#", uri.replace(fragment: "").toString());
753 Expect.equals("s://a:1/b/c?#e", uri.replace(query: "").toString()); 764 Expect.equals("s://a:1/b/c?#e", uri.replace(query: "").toString());
754 Expect.equals("s://a:1?d#e", uri.replace(path: "").toString()); 765 Expect.equals("s://a:1?d#e", uri.replace(path: "").toString());
755 Expect.equals("s://:1/b/c?d#e", uri.replace(host: "").toString()); 766 Expect.equals("s://:1/b/c?d#e", uri.replace(host: "").toString());
767
768 // Test uri.replace on uri with fragment
769 uri = Uri.parse('http://hello.com/fake#fragment');
770 uri = uri.replace(path: "D/E/E");
771 Expect.stringEquals('http://hello.com/D/E/E#fragment', uri.toString());
756 } 772 }
757 773
758 void testRegression28359() { 774 void testRegression28359() {
759 var uri = new Uri(path: "//"); 775 var uri = new Uri(path: "//");
760 // This is an invalid path for a URI reference with no authority 776 // This is an invalid path for a URI reference with no authority
761 // since it looks like an authority. 777 // since it looks like an authority.
762 // Normalized to have an authority. 778 // Normalized to have an authority.
763 Expect.equals("////", "$uri"); 779 Expect.equals("////", "$uri");
764 Expect.equals("//", uri.path); 780 Expect.equals("//", uri.path);
765 Expect.isTrue(uri.hasAuthority, "$uri has authority"); 781 Expect.isTrue(uri.hasAuthority, "$uri has authority");
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 String dump(Uri uri) { 962 String dump(Uri uri) {
947 return "URI: $uri\n" 963 return "URI: $uri\n"
948 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" 964 " Scheme: ${uri.scheme} #${uri.scheme.length}\n"
949 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" 965 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n"
950 " Host: ${uri.host} #${uri.host.length}\n" 966 " Host: ${uri.host} #${uri.host.length}\n"
951 " Port: ${uri.port}\n" 967 " Port: ${uri.port}\n"
952 " Path: ${uri.path} #${uri.path.length}\n" 968 " Path: ${uri.path} #${uri.path.length}\n"
953 " Query: ${uri.query} #${uri.query.length}\n" 969 " Query: ${uri.query} #${uri.query.length}\n"
954 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; 970 " Fragment: ${uri.fragment} #${uri.fragment.length}\n";
955 } 971 }
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