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

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

Issue 16019002: Merge the dart:uri library into dart:core and update the Uri class (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Final cleanup Created 7 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
« no previous file with comments | « tests/corelib/uri_path_test.dart ('k') | tests/corelib/uri_scheme_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6
7 void testInvalidArguments() {
8 }
9
10 void testEncodeQueryComponent() {
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.
13 Expect.equals(
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~",
16 Uri.encodeQueryComponent("!\"#\$%&'()*+,-./:;<=>?@[\\]^_`{|}~"));
17 Expect.equals("+%2B+", Uri.encodeQueryComponent(" + "));
18 Expect.equals("%2B+%2B", Uri.encodeQueryComponent("+ +"));
19 }
20
21 void testQueryParameters() {
22 test(String query, Map<String, String> parameters) {
23 check(uri) {
24 Expect.equals(query, uri.query);
25 if (query.isEmpty) {
26 Expect.equals(query, uri.toString());
27 } else {
28 Expect.equals("?$query", uri.toString());
29 }
30 if (parameters.containsValue(null)) {
31 } else {
32 Expect.mapEquals(parameters, uri.queryParameters);
33 }
34 }
35
36 var uri1 = new Uri(queryParameters: parameters);
37 var uri2 = new Uri(query: query);
38 var uri3 = Uri.parse("?$query");
39 check(uri1);
40 check(uri2);
41 check(uri3);
42 Expect.equals(uri1, uri3);
43 Expect.equals(uri2, uri3);
44 }
45
46 test("", {});
47 test("A", {"A": null});
48 test("A", {"A": ""});
49 test("A=a", {"A": "a"});
50 test("A=+", {"A": " "});
51 test("A=%2B", {"A": "+"});
52 test("A=a&B", {"A": "a", "B": null});
53 test("A=a&B", {"A": "a", "B": ""});
54 test("A=a&B=b", {"A": "a", "B": "b"});
55
56 var unreserved = "-._~0123456789"
57 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
58 "abcdefghijklmnopqrstuvwxyz";
59 var encoded = new StringBuffer();
60 var unencoded = new StringBuffer();
61 for (int i = 32; i < 128; i++) {
62 if (i == 32) {
63 encoded.write("+");
64 } else if (unreserved.indexOf(new String.fromCharCode(i)) != -1) {
65 encoded.writeCharCode(i);
66 } else {
67 encoded.write("%");
68 encoded.write(i.toRadixString(16).toUpperCase());
69 }
70 unencoded.writeCharCode(i);
71 }
72 encoded = encoded.toString();
73 unencoded = unencoded.toString();
74 print(encoded);
75 print(unencoded);
76 test("a=$encoded", {"a": unencoded});
77 test("a=$encoded&b=$encoded", {"a": unencoded, "b": unencoded});
78
79 var map = new Map();
80 map[unencoded] = unencoded;
81 test("$encoded=$encoded", map);
82 }
83
84 testInvalidQueryParameters() {
85 test(String query, Map<String, String> parameters) {
86 check(uri) {
87 Expect.equals(query, uri.query);
88 if (query.isEmpty) {
89 Expect.equals(query, uri.toString());
90 } else {
91 Expect.equals("?$query", uri.toString());
92 }
93 if (parameters.containsValue(null)) {
94 } else {
95 Expect.mapEquals(parameters, uri.queryParameters);
96 }
97 }
98
99 var uri1 = new Uri(query: query);
100 var uri2 = Uri.parse("?$query");
101 check(uri1);
102 check(uri2);
103 Expect.equals(uri1, uri2);
104 }
105
106 test("=", {});
107 test("=xxx", {});
108 test("===", {});
109 test("=xxx=yyy=zzz", {});
110 test("=&=&=", {});
111 test("=xxx&=yyy&=zzz", {});
112 test("&=&=&", {});
113 test("&=xxx&=xxx&", {});
114 }
115
116 main() {
117 testInvalidArguments();
118 testEncodeQueryComponent();
119 testQueryParameters();
120 testInvalidQueryParameters();
121 }
OLDNEW
« no previous file with comments | « tests/corelib/uri_path_test.dart ('k') | tests/corelib/uri_scheme_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698