Chromium Code Reviews| Index: tests/standalone/io/url_encoding_test.dart |
| diff --git a/tests/standalone/io/url_encoding_test.dart b/tests/standalone/io/url_encoding_test.dart |
| index c99346ae5b813f38343280ad00cebef3ea8f7edb..c7f325a3bddd933b5dfad17d41cd69a7128968a9 100644 |
| --- a/tests/standalone/io/url_encoding_test.dart |
| +++ b/tests/standalone/io/url_encoding_test.dart |
| @@ -4,6 +4,7 @@ |
| import "package:expect/expect.dart"; |
| import "dart:async"; |
| +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).
|
| import "dart:utf"; |
| part '../../../sdk/lib/io/io_sink.dart'; |
| @@ -23,19 +24,68 @@ void testParseEncodedString() { |
| } |
| void testParseQueryString() { |
| + test(String queryString, Map<String, String> expected) { |
| + Map<String, String> map = _HttpUtils.splitQueryString(queryString); |
| + for (String key in map.keys) { |
| + Expect.equals(expected[key], map[key]); |
| + } |
| + Expect.setEquals(expected.keys.toSet(), map.keys.toSet()); |
| + } |
| + |
| // The query string includes escaped "?"s, "&"s, "%"s and "="s. |
| // These should not affect the splitting of the string. |
| - String queryString = |
| - '%3F=%3D&foo=bar&%26=%25&sqrt2=%E2%88%9A2&name=Franti%C5%A1ek'; |
| - Map<String, String> map = _HttpUtils.splitQueryString(queryString); |
| - for (String key in map.keys) { |
| - Expect.equals(map[key], { '&' : '%', |
| - 'foo' : 'bar', |
| - '?' : '=', |
| - 'sqrt2' : '\u221A2', |
| - 'name' : 'Franti\u0161ek'}[key]); |
| - } |
| - Expect.setEquals(map.keys.toSet(), ['&', '?', 'foo', 'sqrt2', 'name']); |
| + test('%3F=%3D&foo=bar&%26=%25&sqrt2=%E2%88%9A2&name=Franti%C5%A1ek', |
| + { '&' : '%', |
| + 'foo' : 'bar', |
| + '?' : '=', |
| + 'sqrt2' : '\u221A2', |
| + 'name' : 'Franti\u0161ek'}); |
| + |
| + // Same query string with ; as separator. |
| + test('%3F=%3D;foo=bar;%26=%25;sqrt2=%E2%88%9A2;name=Franti%C5%A1ek', |
| + { '&' : '%', |
| + 'foo' : 'bar', |
| + '?' : '=', |
| + 'sqrt2' : '\u221A2', |
| + 'name' : 'Franti\u0161ek'}); |
| + |
| + // Same query string with alternating ; and & separators. |
| + test('%3F=%3D&foo=bar;%26=%25&sqrt2=%E2%88%9A2;name=Franti%C5%A1ek', |
| + { '&' : '%', |
| + 'foo' : 'bar', |
| + '?' : '=', |
| + 'sqrt2' : '\u221A2', |
| + 'name' : 'Franti\u0161ek'}); |
| + test('%3F=%3D;foo=bar&%26=%25;sqrt2=%E2%88%9A2&name=Franti%C5%A1ek', |
| + { '&' : '%', |
| + 'foo' : 'bar', |
| + '?' : '=', |
| + 'sqrt2' : '\u221A2', |
| + 'name' : 'Franti\u0161ek'}); |
| + |
| + // Corner case tests. |
| + test('', { }); |
| + test('&', { }); |
| + test(';', { }); |
| + test('&;', { }); |
| + test(';&', { }); |
| + test('&&&&', { }); |
| + test(';;;;', { }); |
| + test('a', { 'a' : '' }); |
| + test('&a&', { 'a' : '' }); |
| + test(';a;', { 'a' : '' }); |
| + test('a=', { 'a' : '' }); |
| + test('a=&', { 'a' : '' }); |
| + test('a=;', { 'a' : '' }); |
| + test('a=&b', { 'a' : '', 'b' : '' }); |
| + test('a=;b', { 'a' : '', 'b' : '' }); |
| + test('a=&b', { 'a' : '', 'b' : '' }); |
| + test('a=&b=', { 'a' : '', 'b' : '' }); |
| + |
| + // These are not really a legal query string. |
| + test('=', { }); |
| + test('=x', { }); |
| + test('a==&b===', { 'a' : '=', 'b' : '==' }); |
| } |
| void main() { |