| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "dart:collection"; | |
| 6 | |
| 7 import "package:expect/expect.dart"; | |
| 8 | |
| 9 void testInvalidArguments() { | |
| 10 } | |
| 11 | |
| 12 void testPath() { | |
| 13 void test(s, uri) { | |
| 14 Expect.equals(s, uri.toString()); | |
| 15 Expect.equals(uri, Uri.parse(s)); | |
| 16 } | |
| 17 | |
| 18 test("http:", new Uri(scheme: "http")); | |
| 19 test("http://host/xxx", new Uri(scheme: "http", host: "host", path: "xxx")); | |
| 20 test("http://host/xxx", new Uri(scheme: "http", host: "host", path: "/xxx")); | |
| 21 test("http://host/xxx", | |
| 22 new Uri(scheme: "http", host: "host", pathSegments: ["xxx"])); | |
| 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", path: "/xxx/yyy")); | |
| 27 test("http://host/xxx/yyy", | |
| 28 new Uri(scheme: "http", host: "host", pathSegments: ["xxx", "yyy"])); | |
| 29 | |
| 30 test("urn:", new Uri(scheme: "urn")); | |
| 31 test("urn:xxx", new Uri(scheme: "urn", path: "xxx")); | |
| 32 test("urn:xxx:yyy", new Uri(scheme: "urn", path: "xxx:yyy")); | |
| 33 | |
| 34 Expect.equals(3, new Uri(path: "xxx/yyy/zzz").pathSegments.length); | |
| 35 Expect.equals(3, new Uri(path: "/xxx/yyy/zzz").pathSegments.length); | |
| 36 Expect.equals(3, Uri.parse("http://host/xxx/yyy/zzz").pathSegments.length); | |
| 37 Expect.equals(3, Uri.parse("file:///xxx/yyy/zzz").pathSegments.length); | |
| 38 } | |
| 39 | |
| 40 void testPathSegments() { | |
| 41 void test(String path, List<String> segments) { | |
| 42 void check(uri) { | |
| 43 Expect.equals(path, uri.path); | |
| 44 Expect.equals(path, uri.toString()); | |
| 45 Expect.listEquals(segments, uri.pathSegments); | |
| 46 } | |
| 47 | |
| 48 var uri1 = new Uri(pathSegments: segments); | |
| 49 var uri2 = new Uri(path: path); | |
| 50 check(uri1); | |
| 51 check(uri2); | |
| 52 Expect.equals(uri1, uri2); | |
| 53 } | |
| 54 | |
| 55 test("", []); | |
| 56 test("%20", [" "]); | |
| 57 test("%20/%20%20", [" ", " "]); | |
| 58 test("A", ["A"]); | |
| 59 test("%C3%B8", ["ø"]); | |
| 60 test("%C3%B8/%C3%A5", ["ø", "å"]); | |
| 61 test("%C8%A4/%E5%B9%B3%E4%BB%AE%E5%90%8D", ["Ȥ", "平仮名"]); | |
| 62 test("A/b", ["A", "b"]); | |
| 63 test("A/%25", ["A", "%"]); | |
| 64 test("%2F/a%2Fb", ["/", "a/b"]); | |
| 65 test("name;v=1.1", ["name;v=1.1"]); | |
| 66 test("name,v=1.1", ["name,v=1.1"]); | |
| 67 test("name;v=1.1/name,v=1.1", ["name;v=1.1", "name,v=1.1"]); | |
| 68 | |
| 69 var unreserved = "-._~0123456789" | |
| 70 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| 71 "abcdefghijklmnopqrstuvwxyz"; | |
| 72 var subDelimiters = r"!$&'()*+,;="; | |
| 73 var additionalPathChars = ":@"; | |
| 74 var pchar = unreserved + subDelimiters + additionalPathChars; | |
| 75 | |
| 76 var encoded = new StringBuffer(); | |
| 77 var unencoded = new StringBuffer(); | |
| 78 for (int i = 32; i < 128; i++) { | |
| 79 if (pchar.indexOf(new String.fromCharCode(i)) != -1) { | |
| 80 encoded.writeCharCode(i); | |
| 81 } else { | |
| 82 encoded.write("%"); | |
| 83 encoded.write(i.toRadixString(16).toUpperCase()); | |
| 84 } | |
| 85 unencoded.writeCharCode(i); | |
| 86 } | |
| 87 encoded = encoded.toString(); | |
| 88 unencoded = unencoded.toString(); | |
| 89 test(encoded, [unencoded]); | |
| 90 test(encoded + "/" + encoded, [unencoded, unencoded]); | |
| 91 | |
| 92 Uri uri; | |
| 93 List pathSegments = ["xxx", "yyy", "zzz"]; | |
| 94 | |
| 95 uri = new Uri(pathSegments: pathSegments); | |
| 96 Expect.equals(3, uri.pathSegments.length); | |
| 97 uri = new Uri(pathSegments: pathSegments.where((_) => true)); | |
| 98 Expect.equals(3, uri.pathSegments.length); | |
| 99 uri = new Uri(pathSegments: new DoubleLinkedQueue.from(pathSegments)); | |
| 100 Expect.equals(3, uri.pathSegments.length); | |
| 101 | |
| 102 uri = new Uri(scheme: "http", | |
| 103 host: "host", | |
| 104 pathSegments: pathSegments); | |
| 105 Expect.equals(3, uri.pathSegments.length); | |
| 106 uri = new Uri(scheme: "http", | |
| 107 host: "host", | |
| 108 pathSegments: pathSegments.where((_) => true)); | |
| 109 Expect.equals(3, uri.pathSegments.length); | |
| 110 uri = new Uri(scheme: "http", | |
| 111 host: "host", | |
| 112 pathSegments: new DoubleLinkedQueue.from(pathSegments)); | |
| 113 Expect.equals(3, uri.pathSegments.length); | |
| 114 | |
| 115 uri = new Uri(scheme: "file", | |
| 116 pathSegments: pathSegments); | |
| 117 Expect.equals(3, uri.pathSegments.length); | |
| 118 uri = new Uri(scheme: "file", | |
| 119 pathSegments: pathSegments.where((_) => true)); | |
| 120 Expect.equals(3, uri.pathSegments.length); | |
| 121 uri = new Uri(scheme: "file", | |
| 122 pathSegments: new DoubleLinkedQueue.from(pathSegments)); | |
| 123 Expect.equals(3, uri.pathSegments.length); | |
| 124 } | |
| 125 | |
| 126 void testPathCompare() { | |
| 127 void test(Uri uri1, Uri uri2) { | |
| 128 Expect.equals(uri1, uri2); | |
| 129 Expect.equals(uri2, uri1); | |
| 130 } | |
| 131 | |
| 132 test(new Uri(scheme: "http", host: "host", path: "xxx"), | |
| 133 new Uri(scheme: "http", host: "host", path: "/xxx")); | |
| 134 test(new Uri(scheme: "http", host: "host", pathSegments: ["xxx"]), | |
| 135 new Uri(scheme: "http", host: "host", path: "/xxx")); | |
| 136 test(new Uri(scheme: "http", host: "host", pathSegments: ["xxx"]), | |
| 137 new Uri(scheme: "http", host: "host", path: "xxx")); | |
| 138 test(new Uri(scheme: "file", path: "xxx"), | |
| 139 new Uri(scheme: "file", path: "/xxx")); | |
| 140 test(new Uri(scheme: "file", pathSegments: ["xxx"]), | |
| 141 new Uri(scheme: "file", path: "/xxx")); | |
| 142 test(new Uri(scheme: "file", pathSegments: ["xxx"]), | |
| 143 new Uri(scheme: "file", path: "xxx")); | |
| 144 } | |
| 145 | |
| 146 testPathSegmentsUnmodifiableList() { | |
| 147 void test(list) { | |
| 148 bool isUnsupported(e) => e is UnsupportedError; | |
| 149 | |
| 150 Expect.equals("a", list[0]); | |
| 151 Expect.throws(() => list[0] = "c", isUnsupported); | |
| 152 Expect.equals(2, list.length); | |
| 153 Expect.throws(() => list.length = 1, isUnsupported); | |
| 154 Expect.throws(() => list.add("c"), isUnsupported); | |
| 155 Expect.throws(() => list.addAll(["c", "d"]), isUnsupported); | |
| 156 Expect.listEquals(["b", "a"], list.reversed.toList()); | |
| 157 Expect.throws(() => list.sort(), isUnsupported); | |
| 158 Expect.equals(0, list.indexOf("a")); | |
| 159 Expect.equals(0, list.lastIndexOf("a")); | |
| 160 Expect.throws(() => list.clear(), isUnsupported); | |
| 161 Expect.throws(() => list.insert(1, "c"), isUnsupported); | |
| 162 Expect.throws(() => list.insertAll(1, ["c", "d"]), isUnsupported); | |
| 163 Expect.throws(() => list.setAll(1, ["c", "d"]), isUnsupported); | |
| 164 Expect.throws(() => list.remove("a"), isUnsupported); | |
| 165 Expect.throws(() => list.removeAt(0), isUnsupported); | |
| 166 Expect.throws(() => list.removeLast(), isUnsupported); | |
| 167 Expect.throws(() => list.removeWhere((e) => true), isUnsupported); | |
| 168 Expect.throws(() => list.retainWhere((e) => false), isUnsupported); | |
| 169 Expect.listEquals(["a"], list.sublist(0, 1)); | |
| 170 Expect.listEquals(["a"], list.getRange(0, 1).toList()); | |
| 171 Expect.throws(() => list.setRange(0, 1, ["c"]), isUnsupported); | |
| 172 Expect.throws(() => list.removeRange(0, 1), isUnsupported); | |
| 173 Expect.throws(() => list.fillRange(0, 1, "c"), isUnsupported); | |
| 174 Expect.throws(() => list.replaceRange(0, 1, ["c"]), isUnsupported); | |
| 175 Map map = new Map(); | |
| 176 map[0] = "a"; | |
| 177 map[1] = "b"; | |
| 178 Expect.mapEquals(list.asMap(), map); | |
| 179 } | |
| 180 | |
| 181 test(Uri.parse("a/b").pathSegments); | |
| 182 test(new Uri(pathSegments: ["a", "b"]).pathSegments); | |
| 183 } | |
| 184 | |
| 185 main() { | |
| 186 testInvalidArguments(); | |
| 187 testPath(); | |
| 188 testPathSegments(); | |
| 189 testPathCompare(); | |
| 190 testPathSegmentsUnmodifiableList(); | |
| 191 } | |
| OLD | NEW |