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