| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 void testInvalidArguments() { | 7 void testInvalidArguments() { |
| 8 } | 8 } |
| 9 | 9 |
| 10 void testPath() { | 10 void testPath() { |
| 11 test(s, uri) { | 11 void test(s, uri) { |
| 12 Expect.equals(s, uri.toString()); | 12 Expect.equals(s, uri.toString()); |
| 13 Expect.equals(uri, Uri.parse(s)); | 13 Expect.equals(uri, Uri.parse(s)); |
| 14 } | 14 } |
| 15 | 15 |
| 16 test("http:", new Uri(scheme: "http")); |
| 17 test("http://host/xxx", new Uri(scheme: "http", host: "host", path: "xxx")); |
| 18 test("http://host/xxx", new Uri(scheme: "http", host: "host", path: "/xxx")); |
| 19 test("http://host/xxx", |
| 20 new Uri(scheme: "http", host: "host", pathSegments: ["xxx"])); |
| 21 test("http://host/xxx/yyy", |
| 22 new Uri(scheme: "http", host: "host", path: "xxx/yyy")); |
| 23 test("http://host/xxx/yyy", |
| 24 new Uri(scheme: "http", host: "host", path: "/xxx/yyy")); |
| 25 test("http://host/xxx/yyy", |
| 26 new Uri(scheme: "http", host: "host", pathSegments: ["xxx", "yyy"])); |
| 27 |
| 16 test("urn:", new Uri(scheme: "urn")); | 28 test("urn:", new Uri(scheme: "urn")); |
| 17 test("urn:xxx", new Uri(scheme: "urn", path: "xxx")); | 29 test("urn:xxx", new Uri(scheme: "urn", path: "xxx")); |
| 18 test("urn:xxx:yyy", new Uri(scheme: "urn", path: "xxx:yyy")); | 30 test("urn:xxx:yyy", new Uri(scheme: "urn", path: "xxx:yyy")); |
| 31 |
| 32 Expect.equals(3, new Uri(path: "xxx/yyy/zzz").pathSegments.length); |
| 33 Expect.equals(3, new Uri(path: "/xxx/yyy/zzz").pathSegments.length); |
| 34 Expect.equals(3, Uri.parse("http://host/xxx/yyy/zzz").pathSegments.length); |
| 35 Expect.equals(3, Uri.parse("file:///xxx/yyy/zzz").pathSegments.length); |
| 19 } | 36 } |
| 20 | 37 |
| 21 void testPathSegments() { | 38 void testPathSegments() { |
| 22 test(String path, List<String> segments) { | 39 void test(String path, List<String> segments) { |
| 23 void check(uri) { | 40 void check(uri) { |
| 24 Expect.equals(path, uri.path); | 41 Expect.equals(path, uri.path); |
| 25 Expect.equals(path, uri.toString()); | 42 Expect.equals(path, uri.toString()); |
| 26 Expect.listEquals(segments, uri.pathSegments); | 43 Expect.listEquals(segments, uri.pathSegments); |
| 27 } | 44 } |
| 28 | 45 |
| 29 var uri1 = new Uri(pathSegments: segments); | 46 var uri1 = new Uri(pathSegments: segments); |
| 30 var uri2 = new Uri(path: path); | 47 var uri2 = new Uri(path: path); |
| 31 var uri3 = Uri.parse(path); | 48 var uri3 = Uri.parse(path); |
| 32 check(uri1); | 49 check(uri1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } else { | 82 } else { |
| 66 encoded.write("%"); | 83 encoded.write("%"); |
| 67 encoded.write(i.toRadixString(16).toUpperCase()); | 84 encoded.write(i.toRadixString(16).toUpperCase()); |
| 68 } | 85 } |
| 69 unencoded.writeCharCode(i); | 86 unencoded.writeCharCode(i); |
| 70 } | 87 } |
| 71 encoded = encoded.toString(); | 88 encoded = encoded.toString(); |
| 72 unencoded = unencoded.toString(); | 89 unencoded = unencoded.toString(); |
| 73 test(encoded, [unencoded]); | 90 test(encoded, [unencoded]); |
| 74 test(encoded + "/" + encoded, [unencoded, unencoded]); | 91 test(encoded + "/" + encoded, [unencoded, unencoded]); |
| 92 |
| 93 Uri uri; |
| 94 uri = new Uri(pathSegments: ["xxx", "yyy", "zzz"]); |
| 95 Expect.equals(3, uri.pathSegments.length); |
| 96 uri = new Uri(scheme: "http", |
| 97 host: "host", |
| 98 pathSegments: ["xxx", "yyy", "zzz"]); |
| 99 Expect.equals(3, uri.pathSegments.length); |
| 100 uri = new Uri(scheme: "file", |
| 101 pathSegments: ["xxx", "yyy", "zzz"]); |
| 102 Expect.equals(3, uri.pathSegments.length); |
| 103 } |
| 104 |
| 105 void testPathCompare() { |
| 106 void test(Uri uri1, Uri uri2) { |
| 107 Expect.equals(uri1, uri2); |
| 108 Expect.equals(uri2, uri1); |
| 109 } |
| 110 |
| 111 test(new Uri(scheme: "http", host: "host", path: "xxx"), |
| 112 new Uri(scheme: "http", host: "host", path: "/xxx")); |
| 113 test(new Uri(scheme: "http", host: "host", pathSegments: ["xxx"]), |
| 114 new Uri(scheme: "http", host: "host", path: "/xxx")); |
| 115 test(new Uri(scheme: "http", host: "host", pathSegments: ["xxx"]), |
| 116 new Uri(scheme: "http", host: "host", path: "xxx")); |
| 117 test(new Uri(scheme: "file", path: "xxx"), |
| 118 new Uri(scheme: "file", path: "/xxx")); |
| 119 test(new Uri(scheme: "file", pathSegments: ["xxx"]), |
| 120 new Uri(scheme: "file", path: "/xxx")); |
| 121 test(new Uri(scheme: "file", pathSegments: ["xxx"]), |
| 122 new Uri(scheme: "file", path: "xxx")); |
| 75 } | 123 } |
| 76 | 124 |
| 77 testPathSegmentsUnmodifiableList() { | 125 testPathSegmentsUnmodifiableList() { |
| 78 | 126 void test(list) { |
| 79 test(list) { | |
| 80 bool isUnsupported(e) => e is UnsupportedError; | 127 bool isUnsupported(e) => e is UnsupportedError; |
| 81 | 128 |
| 82 Expect.equals("a", list[0]); | 129 Expect.equals("a", list[0]); |
| 83 Expect.throws(() => list[0] = "c", isUnsupported); | 130 Expect.throws(() => list[0] = "c", isUnsupported); |
| 84 Expect.equals(2, list.length); | 131 Expect.equals(2, list.length); |
| 85 Expect.throws(() => list.length = 1, isUnsupported); | 132 Expect.throws(() => list.length = 1, isUnsupported); |
| 86 Expect.throws(() => list.add("c"), isUnsupported); | 133 Expect.throws(() => list.add("c"), isUnsupported); |
| 87 Expect.throws(() => list.addAll(["c", "d"]), isUnsupported); | 134 Expect.throws(() => list.addAll(["c", "d"]), isUnsupported); |
| 88 Expect.listEquals(["b", "a"], list.reversed.toList()); | 135 Expect.listEquals(["b", "a"], list.reversed.toList()); |
| 89 Expect.throws(() => list.sort(), isUnsupported); | 136 Expect.throws(() => list.sort(), isUnsupported); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 111 } | 158 } |
| 112 | 159 |
| 113 test(Uri.parse("a/b").pathSegments); | 160 test(Uri.parse("a/b").pathSegments); |
| 114 test(new Uri(pathSegments: ["a", "b"]).pathSegments); | 161 test(new Uri(pathSegments: ["a", "b"]).pathSegments); |
| 115 } | 162 } |
| 116 | 163 |
| 117 main() { | 164 main() { |
| 118 testInvalidArguments(); | 165 testInvalidArguments(); |
| 119 testPath(); | 166 testPath(); |
| 120 testPathSegments(); | 167 testPathSegments(); |
| 168 testPathCompare(); |
| 121 testPathSegmentsUnmodifiableList(); | 169 testPathSegmentsUnmodifiableList(); |
| 122 } | 170 } |
| OLD | NEW |