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() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } else if (unreserved.indexOf(new String.fromCharCode(i)) != -1) { | 64 } else if (unreserved.indexOf(new String.fromCharCode(i)) != -1) { |
65 encoded.writeCharCode(i); | 65 encoded.writeCharCode(i); |
66 } else { | 66 } else { |
67 encoded.write("%"); | 67 encoded.write("%"); |
68 encoded.write(i.toRadixString(16).toUpperCase()); | 68 encoded.write(i.toRadixString(16).toUpperCase()); |
69 } | 69 } |
70 unencoded.writeCharCode(i); | 70 unencoded.writeCharCode(i); |
71 } | 71 } |
72 encoded = encoded.toString(); | 72 encoded = encoded.toString(); |
73 unencoded = unencoded.toString(); | 73 unencoded = unencoded.toString(); |
74 print(encoded); | |
75 print(unencoded); | |
76 test("a=$encoded", {"a": unencoded}); | 74 test("a=$encoded", {"a": unencoded}); |
77 test("a=$encoded&b=$encoded", {"a": unencoded, "b": unencoded}); | 75 test("a=$encoded&b=$encoded", {"a": unencoded, "b": unencoded}); |
78 | 76 |
79 var map = new Map(); | 77 var map = new Map(); |
80 map[unencoded] = unencoded; | 78 map[unencoded] = unencoded; |
81 test("$encoded=$encoded", map); | 79 test("$encoded=$encoded", map); |
82 } | 80 } |
83 | 81 |
84 testInvalidQueryParameters() { | 82 testInvalidQueryParameters() { |
85 test(String query, Map<String, String> parameters) { | 83 test(String query, Map<String, String> parameters) { |
(...skipping 20 matching lines...) Expand all Loading... |
106 test("=", {}); | 104 test("=", {}); |
107 test("=xxx", {}); | 105 test("=xxx", {}); |
108 test("===", {}); | 106 test("===", {}); |
109 test("=xxx=yyy=zzz", {}); | 107 test("=xxx=yyy=zzz", {}); |
110 test("=&=&=", {}); | 108 test("=&=&=", {}); |
111 test("=xxx&=yyy&=zzz", {}); | 109 test("=xxx&=yyy&=zzz", {}); |
112 test("&=&=&", {}); | 110 test("&=&=&", {}); |
113 test("&=xxx&=xxx&", {}); | 111 test("&=xxx&=xxx&", {}); |
114 } | 112 } |
115 | 113 |
| 114 testQueryParametersImmutableMap() { |
| 115 test(map) { |
| 116 bool isUnsupported(e) => e is UnsupportedError; |
| 117 |
| 118 Expect.isTrue(map.containsValue("b")); |
| 119 Expect.isTrue(map.containsKey("a")); |
| 120 Expect.equals("b", map["a"]); |
| 121 Expect.throws(() => map["a"] = "c", isUnsupported); |
| 122 Expect.throws(() => map.putIfAbsent("b", () => "e"), isUnsupported); |
| 123 Expect.throws(() => map.remove("a"), isUnsupported); |
| 124 Expect.throws(() => map.clear(), isUnsupported); |
| 125 var count = 0; |
| 126 map.forEach((key, value) => count++); |
| 127 Expect.equals(2, count); |
| 128 Expect.equals(2, map.keys.length); |
| 129 Expect.equals(2, map.values.length); |
| 130 Expect.equals(2, map.length); |
| 131 Expect.isFalse(map.isEmpty); |
| 132 Expect.isTrue(map.isNotEmpty); |
| 133 } |
| 134 |
| 135 test(Uri.parse("?a=b&c=d").queryParameters); |
| 136 test(new Uri(queryParameters: {"a": "b", "c": "d"}).queryParameters); |
| 137 } |
| 138 |
116 main() { | 139 main() { |
117 testInvalidArguments(); | 140 testInvalidArguments(); |
118 testEncodeQueryComponent(); | 141 testEncodeQueryComponent(); |
119 testQueryParameters(); | 142 testQueryParameters(); |
120 testInvalidQueryParameters(); | 143 testInvalidQueryParameters(); |
| 144 testQueryParametersImmutableMap(); |
121 } | 145 } |
OLD | NEW |