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

Side by Side Diff: tests/standalone/io/url_encoding_test.dart

Issue 18576006: Remove _HttpUtils from dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated comments and add encoding tests. Created 7 years, 5 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/standalone/io/http_headers_test.dart ('k') | tests/standalone/standalone.status » ('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 import "dart:async";
7 import "dart:utf";
8 import 'dart:collection';
9
10 part '../../../sdk/lib/io/common.dart';
11 part '../../../sdk/lib/io/io_sink.dart';
12 part "../../../sdk/lib/io/http.dart";
13 part "../../../sdk/lib/io/http_impl.dart";
14 part "../../../sdk/lib/io/http_parser.dart";
15 part "../../../sdk/lib/io/http_utils.dart";
16 part "../../../sdk/lib/io/socket.dart";
17 part "../../../sdk/lib/io/string_transformer.dart";
18
19 void testParseEncodedString() {
20 String encodedString = 'foo+bar%20foobar%25%26';
21 Expect.equals(_HttpUtils.decodeUrlEncodedString(encodedString),
22 'foo bar foobar%&');
23 encodedString = 'A+%2B+B';
24 Expect.equals(_HttpUtils.decodeUrlEncodedString(encodedString),
25 'A + B');
26 }
27
28 void testParseQueryString() {
29 test(String queryString, Map<String, String> expected) {
30 Map<String, String> map = _HttpUtils.splitQueryString(queryString);
31 for (String key in map.keys) {
32 Expect.equals(expected[key], map[key]);
33 }
34 Expect.setEquals(expected.keys.toSet(), map.keys.toSet());
35 }
36
37 // The query string includes escaped "?"s, "&"s, "%"s and "="s.
38 // These should not affect the splitting of the string.
39 test('%3F=%3D&foo=bar&%26=%25&sqrt2=%E2%88%9A2&name=Franti%C5%A1ek',
40 { '&' : '%',
41 'foo' : 'bar',
42 '?' : '=',
43 'sqrt2' : '\u221A2',
44 'name' : 'Franti\u0161ek'});
45
46 // Same query string with ; as separator.
47 test('%3F=%3D;foo=bar;%26=%25;sqrt2=%E2%88%9A2;name=Franti%C5%A1ek',
48 { '&' : '%',
49 'foo' : 'bar',
50 '?' : '=',
51 'sqrt2' : '\u221A2',
52 'name' : 'Franti\u0161ek'});
53
54 // Same query string with alternating ; and & separators.
55 test('%3F=%3D&foo=bar;%26=%25&sqrt2=%E2%88%9A2;name=Franti%C5%A1ek',
56 { '&' : '%',
57 'foo' : 'bar',
58 '?' : '=',
59 'sqrt2' : '\u221A2',
60 'name' : 'Franti\u0161ek'});
61 test('%3F=%3D;foo=bar&%26=%25;sqrt2=%E2%88%9A2&name=Franti%C5%A1ek',
62 { '&' : '%',
63 'foo' : 'bar',
64 '?' : '=',
65 'sqrt2' : '\u221A2',
66 'name' : 'Franti\u0161ek'});
67
68 // Corner case tests.
69 test('', { });
70 test('&', { });
71 test(';', { });
72 test('&;', { });
73 test(';&', { });
74 test('&&&&', { });
75 test(';;;;', { });
76 test('a', { 'a' : '' });
77 test('&a&', { 'a' : '' });
78 test(';a;', { 'a' : '' });
79 test('a=', { 'a' : '' });
80 test('a=&', { 'a' : '' });
81 test('a=;', { 'a' : '' });
82 test('a=&b', { 'a' : '', 'b' : '' });
83 test('a=;b', { 'a' : '', 'b' : '' });
84 test('a=&b', { 'a' : '', 'b' : '' });
85 test('a=&b=', { 'a' : '', 'b' : '' });
86
87 // These are not really a legal query string.
88 test('=', { });
89 test('=x', { });
90 test('a==&b===', { 'a' : '=', 'b' : '==' });
91 }
92
93 void main() {
94 testParseEncodedString();
95 testParseQueryString();
96 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_headers_test.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698