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('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 |
110 void main() { | 147 void main() { |
111 testValidIpv6Uri(); | 148 testValidIpv6Uri(); |
| 149 testParseIPv6Address(); |
112 } | 150 } |
113 | 151 |
OLD | NEW |