| OLD | NEW |
| 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.isTrue(uri.hasQuery); |
| 25 Expect.equals(normalizedQuery, uri.query); | 26 Expect.equals(normalizedQuery, uri.query); |
| 26 Expect.equals("?$normalizedQuery", uri.toString()); | 27 Expect.equals("?$normalizedQuery", uri.toString()); |
| 27 if (parameters.containsValue(null)) { | 28 if (parameters.containsValue(null)) { |
| 28 var map = new Map.from(parameters); | 29 var map = new Map.from(parameters); |
| 29 map.forEach((k, v) { if (v == null) map[k] = ""; }); | 30 map.forEach((k, v) { if (v == null) map[k] = ""; }); |
| 30 Expect.mapEquals(map, uri.queryParameters); | 31 Expect.mapEquals(map, uri.queryParameters); |
| 31 } else { | 32 } else { |
| 32 Expect.mapEquals(parameters, uri.queryParameters); | 33 Expect.mapEquals(parameters, uri.queryParameters); |
| 33 } | 34 } |
| 34 } | 35 } |
| 35 | 36 |
| 36 var uri1 = new Uri(queryParameters: parameters); | 37 var uri1 = new Uri(queryParameters: parameters); |
| 37 var uri2 = new Uri(query: query); | 38 var uri2 = new Uri(query: query); |
| 38 var uri3 = Uri.parse("?$query"); | 39 var uri3 = Uri.parse("?$query"); |
| 39 check(uri1); | 40 check(uri1); |
| 40 check(uri2); | 41 if (query != "") { |
| 42 check(uri2); |
| 43 } else { |
| 44 Expect.isFalse(uri2.hasQuery); |
| 45 } |
| 41 check(uri3); | 46 check(uri3); |
| 42 Expect.equals(uri1, uri3); | 47 Expect.equals(uri1, uri3); |
| 43 Expect.equals(uri2, uri3); | 48 if (query != "") Expect.equals(uri2, uri3); |
| 44 if (parameters.containsValue(null)) { | 49 if (parameters.containsValue(null)) { |
| 45 var map = new Map.from(parameters); | 50 var map = new Map.from(parameters); |
| 46 map.forEach((k, v) { if (v == null) map[k] = ""; }); | 51 map.forEach((k, v) { if (v == null) map[k] = ""; }); |
| 47 Expect.mapEquals(map, Uri.splitQueryString(query)); | 52 Expect.mapEquals(map, Uri.splitQueryString(query)); |
| 48 } else { | 53 } else { |
| 49 Expect.mapEquals(parameters, Uri.splitQueryString(query)); | 54 Expect.mapEquals(parameters, Uri.splitQueryString(query)); |
| 50 } | 55 } |
| 51 } | 56 } |
| 52 | 57 |
| 53 test("", {}); | 58 test("", {}); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 test(new Uri(queryParameters: {"a": "b", "c": "d"}).queryParameters); | 171 test(new Uri(queryParameters: {"a": "b", "c": "d"}).queryParameters); |
| 167 } | 172 } |
| 168 | 173 |
| 169 main() { | 174 main() { |
| 170 testInvalidArguments(); | 175 testInvalidArguments(); |
| 171 testEncodeQueryComponent(); | 176 testEncodeQueryComponent(); |
| 172 testQueryParameters(); | 177 testQueryParameters(); |
| 173 testInvalidQueryParameters(); | 178 testInvalidQueryParameters(); |
| 174 testQueryParametersImmutableMap(); | 179 testQueryParametersImmutableMap(); |
| 175 } | 180 } |
| OLD | NEW |