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

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

Issue 335373003: New Uri.parse and validation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More test. Created 6 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 7
8 void testValidIpv6Uri() { 8 void testValidIpv6Uri() {
9 var path = 'http://[::1]:1234/path?query=5#now'; 9 var path = 'http://[::1]:1234/path?query=5#now';
10 var uri = Uri.parse(path); 10 var uri = Uri.parse(path);
11 Expect.equals('http', uri.scheme); 11 Expect.equals('http', uri.scheme);
12 Expect.equals('::1', uri.host); 12 Expect.equals('::1', uri.host);
13 Expect.equals(1234, uri.port); 13 Expect.equals(1234, uri.port);
14 Expect.equals('/path', uri.path); 14 Expect.equals('/path', uri.path);
15 Expect.equals('query=5', uri.query); 15 Expect.equals('query=5', uri.query);
16 Expect.equals('now', uri.fragment); 16 Expect.equals('now', uri.fragment);
17 Expect.equals(path, uri.toString()); 17 Expect.equals(path, uri.toString());
18 18
19 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8080/index.html'; 19 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8080/index.html';
20 uri = Uri.parse(path); 20 uri = Uri.parse(path);
21 Expect.equals('http', uri.scheme); 21 Expect.equals('http', uri.scheme);
22 Expect.equals('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', uri.host); 22 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
23 Expect.equals(8080, uri.port); 23 Expect.equals(8080, uri.port);
24 Expect.equals('/index.html', uri.path); 24 Expect.equals('/index.html', uri.path);
25 Expect.equals(path, uri.toString()); 25 Expect.equals(path.toLowerCase(), uri.toString());
26 26
27 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html'; 27 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html';
28 uri = Uri.parse(path); 28 uri = Uri.parse(path);
29 Expect.equals('http', uri.scheme); 29 Expect.equals('http', uri.scheme);
30 Expect.equals('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', uri.host); 30 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
31 Expect.equals(80, uri.port); 31 Expect.equals(80, uri.port);
32 Expect.equals('/index.html', uri.path); 32 Expect.equals('/index.html', uri.path);
33 Expect.equals('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]/index.html', 33 Expect.equals('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html',
34 uri.toString()); 34 uri.toString());
35 35
36 path = 'https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:443/index.html'; 36 path = 'https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:443/index.html';
37 uri = Uri.parse(path); 37 uri = Uri.parse(path);
38 Expect.equals('https', uri.scheme); 38 Expect.equals('https', uri.scheme);
39 Expect.equals('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', uri.host); 39 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
40 Expect.equals(443, uri.port); 40 Expect.equals(443, uri.port);
41 Expect.equals('/index.html', uri.path); 41 Expect.equals('/index.html', uri.path);
42 Expect.equals('https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]/index.html', 42 Expect.equals('https://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html',
43 uri.toString()); 43 uri.toString());
44 44
45 path = 'http://[1080:0:0:0:8:800:200C:417A]/index.html'; 45 path = 'http://[1080:0:0:0:8:800:200C:417A]/index.html';
46 uri = Uri.parse(path); 46 uri = Uri.parse(path);
47 Expect.equals('http', uri.scheme); 47 Expect.equals('http', uri.scheme);
48 Expect.equals('1080:0:0:0:8:800:200C:417A', uri.host); 48 Expect.equals('1080:0:0:0:8:800:200c:417a', uri.host);
49 Expect.equals(80, uri.port); 49 Expect.equals(80, uri.port);
50 Expect.equals('/index.html', uri.path); 50 Expect.equals('/index.html', uri.path);
51 Expect.equals(path, uri.toString()); 51 Expect.equals(path.toLowerCase(), uri.toString());
52 52
53 path = 'http://[3ffe:2a00:100:7031::1]'; 53 path = 'http://[3ffe:2a00:100:7031::1]';
54 uri = Uri.parse(path); 54 uri = Uri.parse(path);
55 Expect.equals('http', uri.scheme); 55 Expect.equals('http', uri.scheme);
56 Expect.equals('3ffe:2a00:100:7031::1', uri.host); 56 Expect.equals('3ffe:2a00:100:7031::1', uri.host);
57 Expect.equals(80, uri.port); 57 Expect.equals(80, uri.port);
58 Expect.equals('', uri.path); 58 Expect.equals('', uri.path);
59 Expect.equals(path, uri.toString()); 59 Expect.equals(path, uri.toString());
60 60
61 path = 'http://[1080::8:800:200C:417A]/foo'; 61 path = 'http://[1080::8:800:200C:417A]/foo';
62 uri = Uri.parse(path); 62 uri = Uri.parse(path);
63 Expect.equals('http', uri.scheme); 63 Expect.equals('http', uri.scheme);
64 Expect.equals('1080::8:800:200C:417A', uri.host); 64 Expect.equals('1080::8:800:200c:417a', uri.host);
65 Expect.equals(80, uri.port); 65 Expect.equals(80, uri.port);
66 Expect.equals('/foo', uri.path); 66 Expect.equals('/foo', uri.path);
67 Expect.equals(path, uri.toString()); 67 Expect.equals(path.toLowerCase(), uri.toString());
68 68
69 path = 'http://[::192.9.5.5]/ipng'; 69 path = 'http://[::192.9.5.5]/ipng';
70 uri = Uri.parse(path); 70 uri = Uri.parse(path);
71 Expect.equals('http', uri.scheme); 71 Expect.equals('http', uri.scheme);
72 Expect.equals('::192.9.5.5', uri.host); 72 Expect.equals('::192.9.5.5', uri.host);
73 Expect.equals(80, uri.port); 73 Expect.equals(80, uri.port);
74 Expect.equals('/ipng', uri.path); 74 Expect.equals('/ipng', uri.path);
75 Expect.equals(path, uri.toString()); 75 Expect.equals(path, uri.toString());
76 76
77 path = 'http://[::FFFF:129.144.52.38]:8080/index.html'; 77 path = 'http://[::FFFF:129.144.52.38]:8080/index.html';
78 uri = Uri.parse(path); 78 uri = Uri.parse(path);
79 Expect.equals('http', uri.scheme); 79 Expect.equals('http', uri.scheme);
80 Expect.equals('::FFFF:129.144.52.38', uri.host); 80 Expect.equals('::ffff:129.144.52.38', uri.host);
81 Expect.equals(8080, uri.port); 81 Expect.equals(8080, uri.port);
82 Expect.equals('/index.html', uri.path); 82 Expect.equals('/index.html', uri.path);
83 Expect.equals(path, uri.toString()); 83 Expect.equals(path.toLowerCase(), uri.toString());
84 84
85 path = 'http://[::FFFF:129.144.52.38]:80/index.html'; 85 path = 'http://[::FFFF:129.144.52.38]:80/index.html';
86 uri = Uri.parse(path); 86 uri = Uri.parse(path);
87 Expect.equals('http', uri.scheme); 87 Expect.equals('http', uri.scheme);
88 Expect.equals('::FFFF:129.144.52.38', uri.host); 88 Expect.equals('::ffff:129.144.52.38', uri.host);
89 Expect.equals(80, uri.port); 89 Expect.equals(80, uri.port);
90 Expect.equals('/index.html', uri.path); 90 Expect.equals('/index.html', uri.path);
91 Expect.equals('http://[::FFFF:129.144.52.38]/index.html', uri.toString()); 91 Expect.equals('http://[::ffff:129.144.52.38]/index.html', uri.toString());
92 92
93 path = 'https://[::FFFF:129.144.52.38]:443/index.html'; 93 path = 'https://[::FFFF:129.144.52.38]:443/index.html';
94 uri = Uri.parse(path); 94 uri = Uri.parse(path);
95 Expect.equals('https', uri.scheme); 95 Expect.equals('https', uri.scheme);
96 Expect.equals('::FFFF:129.144.52.38', uri.host); 96 Expect.equals('::ffff:129.144.52.38', uri.host);
97 Expect.equals(443, uri.port); 97 Expect.equals(443, uri.port);
98 Expect.equals('/index.html', uri.path); 98 Expect.equals('/index.html', uri.path);
99 Expect.equals('https://[::FFFF:129.144.52.38]/index.html', uri.toString()); 99 Expect.equals('https://[::ffff:129.144.52.38]/index.html', uri.toString());
100 100
101 path = 'http://[2010:836B:4179::836B:4179]'; 101 path = 'http://[2010:836B:4179::836B:4179]';
102 uri = Uri.parse(path); 102 uri = Uri.parse(path);
103 Expect.equals('http', uri.scheme); 103 Expect.equals('http', uri.scheme);
104 Expect.equals('2010:836B:4179::836B:4179', uri.host); 104 Expect.equals('2010:836b:4179::836b:4179', uri.host);
105 Expect.equals(80, uri.port); 105 Expect.equals(80, uri.port);
106 Expect.equals('', uri.path); 106 Expect.equals('', uri.path);
107 Expect.equals(path, uri.toString()); 107 Expect.equals(path.toLowerCase(), uri.toString());
108 } 108 }
109 109
110 110
111 void testParseIPv6Address() { 111 void testParseIPv6Address() {
112 void pass(String host, List<int> expected) { 112 void pass(String host, List<int> expected) {
113 Expect.listEquals(expected, Uri.parseIPv6Address(host)); 113 Expect.listEquals(expected, Uri.parseIPv6Address(host));
114 } 114 }
115 void fail(String host) { 115 void fail(String host) {
116 Expect.throws(() => Uri.parseIPv6Address(host), 116 Expect.throws(() => Uri.parseIPv6Address(host),
117 (e) => e is FormatException); 117 (e) => e is FormatException);
(...skipping 24 matching lines...) Expand all
142 pass('2010:836B:4179:0000:0000:0000:127.0.0.1', 142 pass('2010:836B:4179:0000:0000:0000:127.0.0.1',
143 [32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1] ); 143 [32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1] );
144 } 144 }
145 145
146 146
147 void main() { 147 void main() {
148 testValidIpv6Uri(); 148 testValidIpv6Uri();
149 testParseIPv6Address(); 149 testParseIPv6Address();
150 } 150 }
151 151
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698