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

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

Issue 2983123002: Migrate test block 30 + corelib portion of block 31 to Dart 2.0. (Closed)
Patch Set: Addressed Bob's comments Created 3 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:expect/expect.dart';
6
7 void testValidIpv6Uri() {
8 var path = 'http://[::1]:1234/path?query=5#now';
9 var uri = Uri.parse(path);
10 Expect.equals('http', uri.scheme);
11 Expect.equals('::1', uri.host);
12 Expect.equals(1234, uri.port);
13 Expect.equals('/path', uri.path);
14 Expect.equals('query=5', uri.query);
15 Expect.equals('now', uri.fragment);
16 Expect.equals(path, uri.toString());
17
18 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8080/index.html';
19 uri = Uri.parse(path);
20 Expect.equals('http', uri.scheme);
21 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
22 Expect.equals(8080, uri.port);
23 Expect.equals('/index.html', uri.path);
24 Expect.equals(path.toLowerCase(), uri.toString());
25
26 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html';
27 uri = Uri.parse(path);
28 Expect.equals('http', uri.scheme);
29 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
30 Expect.equals(80, uri.port);
31 Expect.equals('/index.html', uri.path);
32 Expect.equals('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html',
33 uri.toString());
34
35 path = 'https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:443/index.html';
36 uri = Uri.parse(path);
37 Expect.equals('https', uri.scheme);
38 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
39 Expect.equals(443, uri.port);
40 Expect.equals('/index.html', uri.path);
41 Expect.equals('https://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html',
42 uri.toString());
43
44 path = 'http://[1080:0:0:0:8:800:200C:417A]/index.html';
45 uri = Uri.parse(path);
46 Expect.equals('http', uri.scheme);
47 Expect.equals('1080:0:0:0:8:800:200c:417a', uri.host);
48 Expect.equals(80, uri.port);
49 Expect.equals('/index.html', uri.path);
50 Expect.equals(path.toLowerCase(), uri.toString());
51
52 path = 'http://[3ffe:2a00:100:7031::1]';
53 uri = Uri.parse(path);
54 Expect.equals('http', uri.scheme);
55 Expect.equals('3ffe:2a00:100:7031::1', uri.host);
56 Expect.equals(80, uri.port);
57 Expect.equals('', uri.path);
58 Expect.equals(path, uri.toString());
59
60 path = 'http://[1080::8:800:200C:417A]/foo';
61 uri = Uri.parse(path);
62 Expect.equals('http', uri.scheme);
63 Expect.equals('1080::8:800:200c:417a', uri.host);
64 Expect.equals(80, uri.port);
65 Expect.equals('/foo', uri.path);
66 Expect.equals(path.toLowerCase(), uri.toString());
67
68 path = 'http://[::192.9.5.5]/ipng';
69 uri = Uri.parse(path);
70 Expect.equals('http', uri.scheme);
71 Expect.equals('::192.9.5.5', uri.host);
72 Expect.equals(80, uri.port);
73 Expect.equals('/ipng', uri.path);
74 Expect.equals(path, uri.toString());
75
76 path = 'http://[::FFFF:129.144.52.38]:8080/index.html';
77 uri = Uri.parse(path);
78 Expect.equals('http', uri.scheme);
79 Expect.equals('::ffff:129.144.52.38', uri.host);
80 Expect.equals(8080, uri.port);
81 Expect.equals('/index.html', uri.path);
82 Expect.equals(path.toLowerCase(), uri.toString());
83
84 path = 'http://[::FFFF:129.144.52.38]:80/index.html';
85 uri = Uri.parse(path);
86 Expect.equals('http', uri.scheme);
87 Expect.equals('::ffff:129.144.52.38', uri.host);
88 Expect.equals(80, uri.port);
89 Expect.equals('/index.html', uri.path);
90 Expect.equals('http://[::ffff:129.144.52.38]/index.html', uri.toString());
91
92 path = 'https://[::FFFF:129.144.52.38]:443/index.html';
93 uri = Uri.parse(path);
94 Expect.equals('https', uri.scheme);
95 Expect.equals('::ffff:129.144.52.38', uri.host);
96 Expect.equals(443, uri.port);
97 Expect.equals('/index.html', uri.path);
98 Expect.equals('https://[::ffff:129.144.52.38]/index.html', uri.toString());
99
100 path = 'http://[2010:836B:4179::836B:4179]';
101 uri = Uri.parse(path);
102 Expect.equals('http', uri.scheme);
103 Expect.equals('2010:836b:4179::836b:4179', uri.host);
104 Expect.equals(80, uri.port);
105 Expect.equals('', uri.path);
106 Expect.equals(path.toLowerCase(), uri.toString());
107 }
108
109 void testParseIPv6Address() {
110 void pass(String host, List<int> expected) {
111 Expect.listEquals(expected, Uri.parseIPv6Address(host));
112 }
113
114 void fail(String host) {
115 Expect.throws(
116 () => Uri.parseIPv6Address(host), (e) => e is FormatException);
117 }
118
119 pass('::127.0.0.1', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]);
120 pass('0::127.0.0.1', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]);
121 pass('::', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
122 pass('0::', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
123 fail(':0::127.0.0.1');
124 fail('0:::');
125 fail(':::');
126 fail('::0:');
127 fail('::0::');
128 fail('::0::0');
129 fail('00000::0');
130 fail('-1::0');
131 fail('-AAA::0');
132 fail('0::127.0.0.1:0');
133 fail('0::127.0.0');
134 pass('0::1111', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17]);
135 pass('2010:836B:4179::836B:4179',
136 [32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 131, 107, 65, 121]);
137 fail('2010:836B:4179:0000:127.0.0.1');
138 fail('2010:836B:4179:0000:0000:127.0.0.1');
139 fail('2010:836B:4179:0000:0000:0000::127.0.0.1');
140 fail('2010:836B:4179:0000:0000:0000:0000:127.0.0.1');
141 pass('2010:836B:4179:0000:0000:0000:127.0.0.1',
142 [32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]);
143 }
144
145 void main() {
146 testValidIpv6Uri();
147 testParseIPv6Address();
148 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/uri_ipv4_test.dart ('k') | tests/corelib_strong/uri_normalize_path_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698