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

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

Issue 352093003: Try to retain original structure of URI. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 void testInvalidArguments() { 7 void testInvalidArguments() {
8 } 8 }
9 9
10 void testEncodeQueryComponent() { 10 void testEncodeQueryComponent() {
11 // This exact data is from posting a form in Chrome 26 with the one 11 // This exact data is from posting a form in Chrome 26 with the one
12 // exception that * is encoded as %30 and ~ is not encoded as %7E. 12 // exception that * is encoded as %30 and ~ is not encoded as %7E.
13 Expect.equals( 13 Expect.equals(
14 "%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F%" 14 "%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F%"
15 "3A%3B%3C%3D%3E%3F%40%5B%5C%5D%5E_%60%7B%7C%7D~", 15 "3A%3B%3C%3D%3E%3F%40%5B%5C%5D%5E_%60%7B%7C%7D~",
16 Uri.encodeQueryComponent("!\"#\$%&'()*+,-./:;<=>?@[\\]^_`{|}~")); 16 Uri.encodeQueryComponent("!\"#\$%&'()*+,-./:;<=>?@[\\]^_`{|}~"));
17 Expect.equals("+%2B+", Uri.encodeQueryComponent(" + ")); 17 Expect.equals("+%2B+", Uri.encodeQueryComponent(" + "));
18 Expect.equals("%2B+%2B", Uri.encodeQueryComponent("+ +")); 18 Expect.equals("%2B+%2B", Uri.encodeQueryComponent("+ +"));
19 } 19 }
20 20
21 void testQueryParameters() { 21 void testQueryParameters() {
22 test(String query, Map<String, String> parameters, [String normalizedQuery]) { 22 test(String query, Map<String, String> parameters, [String normalizedQuery]) {
23 if (normalizedQuery == null) normalizedQuery = query; 23 if (normalizedQuery == null) normalizedQuery = query;
24 check(uri) { 24 check(uri) {
25 Expect.equals(normalizedQuery, uri.query); 25 Expect.equals(normalizedQuery, uri.query);
26 if (query.isEmpty) { 26 Expect.equals("?$normalizedQuery", uri.toString());
27 Expect.equals(normalizedQuery, uri.toString());
28 } else {
29 Expect.equals("?$normalizedQuery", uri.toString());
30 }
31 if (parameters.containsValue(null)) { 27 if (parameters.containsValue(null)) {
32 var map = new Map.from(parameters); 28 var map = new Map.from(parameters);
33 map.forEach((k, v) { if (v == null) map[k] = ""; }); 29 map.forEach((k, v) { if (v == null) map[k] = ""; });
34 Expect.mapEquals(map, uri.queryParameters); 30 Expect.mapEquals(map, uri.queryParameters);
35 } else { 31 } else {
36 Expect.mapEquals(parameters, uri.queryParameters); 32 Expect.mapEquals(parameters, uri.queryParameters);
37 } 33 }
38 } 34 }
39 35
40 var uri1 = new Uri(queryParameters: parameters); 36 var uri1 = new Uri(queryParameters: parameters);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 test(new Uri(queryParameters: {"a": "b", "c": "d"}).queryParameters); 166 test(new Uri(queryParameters: {"a": "b", "c": "d"}).queryParameters);
171 } 167 }
172 168
173 main() { 169 main() {
174 testInvalidArguments(); 170 testInvalidArguments();
175 testEncodeQueryComponent(); 171 testEncodeQueryComponent();
176 testQueryParameters(); 172 testQueryParameters();
177 testInvalidQueryParameters(); 173 testInvalidQueryParameters();
178 testQueryParametersImmutableMap(); 174 testQueryParametersImmutableMap();
179 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698