OLD | NEW |
---|---|
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); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(0, uri.port); | 105 Expect.equals(0, uri.port); |
106 Expect.equals('', uri.path); | 106 Expect.equals('', uri.path); |
107 Expect.equals(path, uri.toString()); | 107 Expect.equals(path, uri.toString()); |
108 } | 108 } |
109 | 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('0::127.0.0.1:0'); | |
131 fail('0::127.0.0'); | |
132 pass('0::1111', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17]); | |
133 pass('2010:836B:4179::836B:4179', | |
134 [32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 131, 107, 65, 121] ); | |
Søren Gjesse
2013/09/10 12:18:03
Maybe add a test without wildcards both with and w
Anders Johnsen
2013/09/11 12:58:31
Done.
| |
135 } | |
136 | |
137 | |
110 void main() { | 138 void main() { |
111 testValidIpv6Uri(); | 139 testValidIpv6Uri(); |
140 testParseIPv6Address(); | |
112 } | 141 } |
113 | 142 |
OLD | NEW |