Chromium Code Reviews| 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 import "dart:async"; | 6 import "dart:async"; |
| 7 import 'dart:math'; | |
|
Mads Ager (google)
2013/05/15 09:17:35
Where are you using dart:math here?
Søren Gjesse
2013/05/15 09:22:18
I am not (at one point I had min and max in here).
| |
| 7 import "dart:utf"; | 8 import "dart:utf"; |
| 8 | 9 |
| 9 part '../../../sdk/lib/io/io_sink.dart'; | 10 part '../../../sdk/lib/io/io_sink.dart'; |
| 10 part "../../../sdk/lib/io/http.dart"; | 11 part "../../../sdk/lib/io/http.dart"; |
| 11 part "../../../sdk/lib/io/http_impl.dart"; | 12 part "../../../sdk/lib/io/http_impl.dart"; |
| 12 part "../../../sdk/lib/io/http_parser.dart"; | 13 part "../../../sdk/lib/io/http_parser.dart"; |
| 13 part "../../../sdk/lib/io/http_utils.dart"; | 14 part "../../../sdk/lib/io/http_utils.dart"; |
| 14 part "../../../sdk/lib/io/socket.dart"; | 15 part "../../../sdk/lib/io/socket.dart"; |
| 15 | 16 |
| 16 void testParseEncodedString() { | 17 void testParseEncodedString() { |
| 17 String encodedString = 'foo+bar%20foobar%25%26'; | 18 String encodedString = 'foo+bar%20foobar%25%26'; |
| 18 Expect.equals(_HttpUtils.decodeUrlEncodedString(encodedString), | 19 Expect.equals(_HttpUtils.decodeUrlEncodedString(encodedString), |
| 19 'foo bar foobar%&'); | 20 'foo bar foobar%&'); |
| 20 encodedString = 'A+%2B+B'; | 21 encodedString = 'A+%2B+B'; |
| 21 Expect.equals(_HttpUtils.decodeUrlEncodedString(encodedString), | 22 Expect.equals(_HttpUtils.decodeUrlEncodedString(encodedString), |
| 22 'A + B'); | 23 'A + B'); |
| 23 } | 24 } |
| 24 | 25 |
| 25 void testParseQueryString() { | 26 void testParseQueryString() { |
| 27 test(String queryString, Map<String, String> expected) { | |
| 28 Map<String, String> map = _HttpUtils.splitQueryString(queryString); | |
| 29 for (String key in map.keys) { | |
| 30 Expect.equals(expected[key], map[key]); | |
| 31 } | |
| 32 Expect.setEquals(expected.keys.toSet(), map.keys.toSet()); | |
| 33 } | |
| 34 | |
| 26 // The query string includes escaped "?"s, "&"s, "%"s and "="s. | 35 // The query string includes escaped "?"s, "&"s, "%"s and "="s. |
| 27 // These should not affect the splitting of the string. | 36 // These should not affect the splitting of the string. |
| 28 String queryString = | 37 test('%3F=%3D&foo=bar&%26=%25&sqrt2=%E2%88%9A2&name=Franti%C5%A1ek', |
| 29 '%3F=%3D&foo=bar&%26=%25&sqrt2=%E2%88%9A2&name=Franti%C5%A1ek'; | 38 { '&' : '%', |
| 30 Map<String, String> map = _HttpUtils.splitQueryString(queryString); | 39 'foo' : 'bar', |
| 31 for (String key in map.keys) { | 40 '?' : '=', |
| 32 Expect.equals(map[key], { '&' : '%', | 41 'sqrt2' : '\u221A2', |
| 33 'foo' : 'bar', | 42 'name' : 'Franti\u0161ek'}); |
| 34 '?' : '=', | 43 |
| 35 'sqrt2' : '\u221A2', | 44 // Same query string with ; as separator. |
| 36 'name' : 'Franti\u0161ek'}[key]); | 45 test('%3F=%3D;foo=bar;%26=%25;sqrt2=%E2%88%9A2;name=Franti%C5%A1ek', |
| 37 } | 46 { '&' : '%', |
| 38 Expect.setEquals(map.keys.toSet(), ['&', '?', 'foo', 'sqrt2', 'name']); | 47 'foo' : 'bar', |
| 48 '?' : '=', | |
| 49 'sqrt2' : '\u221A2', | |
| 50 'name' : 'Franti\u0161ek'}); | |
| 51 | |
| 52 // Same query string with alternating ; and & separators. | |
| 53 test('%3F=%3D&foo=bar;%26=%25&sqrt2=%E2%88%9A2;name=Franti%C5%A1ek', | |
| 54 { '&' : '%', | |
| 55 'foo' : 'bar', | |
| 56 '?' : '=', | |
| 57 'sqrt2' : '\u221A2', | |
| 58 'name' : 'Franti\u0161ek'}); | |
| 59 test('%3F=%3D;foo=bar&%26=%25;sqrt2=%E2%88%9A2&name=Franti%C5%A1ek', | |
| 60 { '&' : '%', | |
| 61 'foo' : 'bar', | |
| 62 '?' : '=', | |
| 63 'sqrt2' : '\u221A2', | |
| 64 'name' : 'Franti\u0161ek'}); | |
| 65 | |
| 66 // Corner case tests. | |
| 67 test('', { }); | |
| 68 test('&', { }); | |
| 69 test(';', { }); | |
| 70 test('&;', { }); | |
| 71 test(';&', { }); | |
| 72 test('&&&&', { }); | |
| 73 test(';;;;', { }); | |
| 74 test('a', { 'a' : '' }); | |
| 75 test('&a&', { 'a' : '' }); | |
| 76 test(';a;', { 'a' : '' }); | |
| 77 test('a=', { 'a' : '' }); | |
| 78 test('a=&', { 'a' : '' }); | |
| 79 test('a=;', { 'a' : '' }); | |
| 80 test('a=&b', { 'a' : '', 'b' : '' }); | |
| 81 test('a=;b', { 'a' : '', 'b' : '' }); | |
| 82 test('a=&b', { 'a' : '', 'b' : '' }); | |
| 83 test('a=&b=', { 'a' : '', 'b' : '' }); | |
| 84 | |
| 85 // These are not really a legal query string. | |
| 86 test('=', { }); | |
| 87 test('=x', { }); | |
| 88 test('a==&b===', { 'a' : '=', 'b' : '==' }); | |
| 39 } | 89 } |
| 40 | 90 |
| 41 void main() { | 91 void main() { |
| 42 testParseEncodedString(); | 92 testParseEncodedString(); |
| 43 testParseQueryString(); | 93 testParseQueryString(); |
| 44 } | 94 } |
| OLD | NEW |