| 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 | |
| 8 void testValidIpv6Uri() { | 7 void testValidIpv6Uri() { |
| 9 var path = 'http://[::1]:1234/path?query=5#now'; | 8 var path = 'http://[::1]:1234/path?query=5#now'; |
| 10 var uri = Uri.parse(path); | 9 var uri = Uri.parse(path); |
| 11 Expect.equals('http', uri.scheme); | 10 Expect.equals('http', uri.scheme); |
| 12 Expect.equals('::1', uri.host); | 11 Expect.equals('::1', uri.host); |
| 13 Expect.equals(1234, uri.port); | 12 Expect.equals(1234, uri.port); |
| 14 Expect.equals('/path', uri.path); | 13 Expect.equals('/path', uri.path); |
| 15 Expect.equals('query=5', uri.query); | 14 Expect.equals('query=5', uri.query); |
| 16 Expect.equals('now', uri.fragment); | 15 Expect.equals('now', uri.fragment); |
| 17 Expect.equals(path, uri.toString()); | 16 Expect.equals(path, uri.toString()); |
| 18 | 17 |
| 19 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8080/index.html'; | 18 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8080/index.html'; |
| 20 uri = Uri.parse(path); | 19 uri = Uri.parse(path); |
| 21 Expect.equals('http', uri.scheme); | 20 Expect.equals('http', uri.scheme); |
| 22 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host); | 21 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host); |
| 23 Expect.equals(8080, uri.port); | 22 Expect.equals(8080, uri.port); |
| 24 Expect.equals('/index.html', uri.path); | 23 Expect.equals('/index.html', uri.path); |
| 25 Expect.equals(path.toLowerCase(), uri.toString()); | 24 Expect.equals(path.toLowerCase(), uri.toString()); |
| 26 | 25 |
| 27 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html'; | 26 path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html'; |
| 28 uri = Uri.parse(path); | 27 uri = Uri.parse(path); |
| 29 Expect.equals('http', uri.scheme); | 28 Expect.equals('http', uri.scheme); |
| 30 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host); | 29 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host); |
| 31 Expect.equals(80, uri.port); | 30 Expect.equals(80, uri.port); |
| 32 Expect.equals('/index.html', uri.path); | 31 Expect.equals('/index.html', uri.path); |
| 33 Expect.equals('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html', | 32 Expect.equals('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html', |
| 34 uri.toString()); | 33 uri.toString()); |
| 35 | 34 |
| 36 path = 'https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:443/index.html'; | 35 path = 'https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:443/index.html'; |
| 37 uri = Uri.parse(path); | 36 uri = Uri.parse(path); |
| 38 Expect.equals('https', uri.scheme); | 37 Expect.equals('https', uri.scheme); |
| 39 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host); | 38 Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host); |
| 40 Expect.equals(443, uri.port); | 39 Expect.equals(443, uri.port); |
| 41 Expect.equals('/index.html', uri.path); | 40 Expect.equals('/index.html', uri.path); |
| 42 Expect.equals('https://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html', | 41 Expect.equals('https://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html', |
| 43 uri.toString()); | 42 uri.toString()); |
| 44 | 43 |
| 45 path = 'http://[1080:0:0:0:8:800:200C:417A]/index.html'; | 44 path = 'http://[1080:0:0:0:8:800:200C:417A]/index.html'; |
| 46 uri = Uri.parse(path); | 45 uri = Uri.parse(path); |
| 47 Expect.equals('http', uri.scheme); | 46 Expect.equals('http', uri.scheme); |
| 48 Expect.equals('1080:0:0:0:8:800:200c:417a', uri.host); | 47 Expect.equals('1080:0:0:0:8:800:200c:417a', uri.host); |
| 49 Expect.equals(80, uri.port); | 48 Expect.equals(80, uri.port); |
| 50 Expect.equals('/index.html', uri.path); | 49 Expect.equals('/index.html', uri.path); |
| 51 Expect.equals(path.toLowerCase(), uri.toString()); | 50 Expect.equals(path.toLowerCase(), uri.toString()); |
| 52 | 51 |
| 53 path = 'http://[3ffe:2a00:100:7031::1]'; | 52 path = 'http://[3ffe:2a00:100:7031::1]'; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 99 |
| 101 path = 'http://[2010:836B:4179::836B:4179]'; | 100 path = 'http://[2010:836B:4179::836B:4179]'; |
| 102 uri = Uri.parse(path); | 101 uri = Uri.parse(path); |
| 103 Expect.equals('http', uri.scheme); | 102 Expect.equals('http', uri.scheme); |
| 104 Expect.equals('2010:836b:4179::836b:4179', uri.host); | 103 Expect.equals('2010:836b:4179::836b:4179', uri.host); |
| 105 Expect.equals(80, uri.port); | 104 Expect.equals(80, uri.port); |
| 106 Expect.equals('', uri.path); | 105 Expect.equals('', uri.path); |
| 107 Expect.equals(path.toLowerCase(), uri.toString()); | 106 Expect.equals(path.toLowerCase(), uri.toString()); |
| 108 } | 107 } |
| 109 | 108 |
| 110 | |
| 111 void testParseIPv6Address() { | 109 void testParseIPv6Address() { |
| 112 void pass(String host, List<int> expected) { | 110 void pass(String host, List<int> expected) { |
| 113 Expect.listEquals(expected, Uri.parseIPv6Address(host)); | 111 Expect.listEquals(expected, Uri.parseIPv6Address(host)); |
| 114 } | 112 } |
| 113 |
| 115 void fail(String host) { | 114 void fail(String host) { |
| 116 Expect.throws(() => Uri.parseIPv6Address(host), | 115 Expect.throws( |
| 117 (e) => e is FormatException); | 116 () => Uri.parseIPv6Address(host), (e) => e is FormatException); |
| 118 } | 117 } |
| 119 | 118 |
| 120 pass('::127.0.0.1', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]); | 119 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]); | 120 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]); | 121 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]); | 122 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'); | 123 fail(':0::127.0.0.1'); |
| 125 fail('0:::'); | 124 fail('0:::'); |
| 126 fail(':::'); | 125 fail(':::'); |
| 127 fail('::0:'); | 126 fail('::0:'); |
| 128 fail('::0::'); | 127 fail('::0::'); |
| 129 fail('::0::0'); | 128 fail('::0::0'); |
| 130 fail('00000::0'); | 129 fail('00000::0'); |
| 131 fail('-1::0'); | 130 fail('-1::0'); |
| 132 fail('-AAA::0'); | 131 fail('-AAA::0'); |
| 133 fail('0::127.0.0.1:0'); | 132 fail('0::127.0.0.1:0'); |
| 134 fail('0::127.0.0'); | 133 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]); | 134 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', | 135 pass('2010:836B:4179::836B:4179', |
| 137 [32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 131, 107, 65, 121] ); | 136 [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'); | 137 fail('2010:836B:4179:0000:127.0.0.1'); |
| 139 fail('2010:836B:4179:0000:0000:127.0.0.1'); | 138 fail('2010:836B:4179:0000:0000:127.0.0.1'); |
| 140 fail('2010:836B:4179:0000:0000:0000::127.0.0.1'); | 139 fail('2010:836B:4179:0000:0000:0000::127.0.0.1'); |
| 141 fail('2010:836B:4179:0000:0000:0000:0000:127.0.0.1'); | 140 fail('2010:836B:4179:0000:0000:0000:0000:127.0.0.1'); |
| 142 pass('2010:836B:4179:0000:0000:0000:127.0.0.1', | 141 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] ); | 142 [32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]); |
| 144 } | 143 } |
| 145 | 144 |
| 146 | |
| 147 void main() { | 145 void main() { |
| 148 testValidIpv6Uri(); | 146 testValidIpv6Uri(); |
| 149 testParseIPv6Address(); | 147 testParseIPv6Address(); |
| 150 } | 148 } |
| 151 | |
| OLD | NEW |