Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: tests/corelib/uri_file_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 testFileUri() { 7 testFileUri() {
8 final unsupported = new UnsupportedError(""); 8 final unsupported = new UnsupportedError("");
9 9
10 var tests = [ 10 var tests = [
11 ["", "", ""], 11 ["", "", ""],
12 ["relative", "relative", "relative"], 12 ["relative", "relative", "relative"],
13 ["relative/", "relative/", "relative\\"], 13 ["relative/", "relative/", "relative\\"],
14 ["a%20b", "a b", "a b"], 14 ["a%20b", "a b", "a b"],
15 ["a%20b/", "a b/", "a b\\"], 15 ["a%20b/", "a b/", "a b\\"],
16 ["a/b", "a/b", "a\\b"], 16 ["a/b", "a/b", "a\\b"],
17 ["a/b/", "a/b/", "a\\b\\"], 17 ["a/b/", "a/b/", "a\\b\\"],
18 ["a%20b/c%20d", "a b/c d", "a b\\c d"], 18 ["a%20b/c%20d", "a b/c d", "a b\\c d"],
19 ["a%20b/c%20d/", "a b/c d/", "a b\\c d\\"], 19 ["a%20b/c%20d/", "a b/c d/", "a b\\c d\\"],
20
21 ["file:///absolute", "/absolute", "\\absolute"], 20 ["file:///absolute", "/absolute", "\\absolute"],
22 ["file:///absolute", "/absolute", "\\absolute"], 21 ["file:///absolute", "/absolute", "\\absolute"],
23 ["file:///a/b", "/a/b", "\\a\\b"], 22 ["file:///a/b", "/a/b", "\\a\\b"],
24 ["file:///a/b", "/a/b", "\\a\\b"], 23 ["file:///a/b", "/a/b", "\\a\\b"],
25
26 ["file://server/a/b", unsupported, "\\\\server\\a\\b"], 24 ["file://server/a/b", unsupported, "\\\\server\\a\\b"],
27 ["file://server/a/b/", unsupported, "\\\\server\\a\\b\\"], 25 ["file://server/a/b/", unsupported, "\\\\server\\a\\b\\"],
28
29 ["file:///C:/", "/C:/", "C:\\"], 26 ["file:///C:/", "/C:/", "C:\\"],
30 ["file:///C:/a/b", "/C:/a/b", "C:\\a\\b"], 27 ["file:///C:/a/b", "/C:/a/b", "C:\\a\\b"],
31 ["file:///C:/a/b/", "/C:/a/b/", "C:\\a\\b\\"], 28 ["file:///C:/a/b/", "/C:/a/b/", "C:\\a\\b\\"],
32
33 ["http:/a/b", unsupported, unsupported], 29 ["http:/a/b", unsupported, unsupported],
34 ["https:/a/b", unsupported, unsupported], 30 ["https:/a/b", unsupported, unsupported],
35 ["urn:a:b", unsupported, unsupported], 31 ["urn:a:b", unsupported, unsupported],
36 ]; 32 ];
37 33
38 void check(String s, filePath, bool windows) { 34 void check(String s, filePath, bool windows) {
39 Uri uri = Uri.parse(s); 35 Uri uri = Uri.parse(s);
40 if (filePath is Error) { 36 if (filePath is Error) {
41 if (filePath is UnsupportedError) { 37 if (filePath is UnsupportedError) {
42 Expect.throws(() => uri.toFilePath(windows: windows), 38 Expect.throws(() => uri.toFilePath(windows: windows),
43 (e) => e is UnsupportedError); 39 (e) => e is UnsupportedError);
44 } else { 40 } else {
45 Expect.throws(() => uri.toFilePath(windows: windows)); 41 Expect.throws(() => uri.toFilePath(windows: windows));
46 } 42 }
47 } else { 43 } else {
48 Expect.equals(filePath, uri.toFilePath(windows: windows)); 44 Expect.equals(filePath, uri.toFilePath(windows: windows));
49 Expect.equals( 45 Expect.equals(s, new Uri.file(filePath, windows: windows).toString());
50 s, new Uri.file(filePath, windows: windows).toString());
51 } 46 }
52 } 47 }
53 48
54 for (var test in tests) { 49 for (var test in tests) {
55 check(test[0], test[1], false); 50 check(test[0], test[1], false);
56 check(test[0], test[2], true); 51 check(test[0], test[2], true);
57 } 52 }
58 53
59 Uri uri; 54 Uri uri;
60 uri = Uri.parse("file:a"); 55 uri = Uri.parse("file:a");
61 Expect.equals("/a", uri.toFilePath(windows: false)); 56 Expect.equals("/a", uri.toFilePath(windows: false));
62 Expect.equals("\\a", uri.toFilePath(windows: true)); 57 Expect.equals("\\a", uri.toFilePath(windows: true));
63 uri = Uri.parse("file:a/"); 58 uri = Uri.parse("file:a/");
64 Expect.equals("/a/", uri.toFilePath(windows: false)); 59 Expect.equals("/a/", uri.toFilePath(windows: false));
65 Expect.equals("\\a\\", uri.toFilePath(windows: true)); 60 Expect.equals("\\a\\", uri.toFilePath(windows: true));
66 } 61 }
67 62
68 testFileUriWindowsSlash() { 63 testFileUriWindowsSlash() {
69 var tests = [ 64 var tests = [
70 ["", "", ""], 65 ["", "", ""],
71 ["relative", "relative", "relative"], 66 ["relative", "relative", "relative"],
72 ["relative/", "relative/", "relative\\"], 67 ["relative/", "relative/", "relative\\"],
73 ["a%20b", "a b", "a b"], 68 ["a%20b", "a b", "a b"],
74 ["a%20b/", "a b/", "a b\\"], 69 ["a%20b/", "a b/", "a b\\"],
75 ["a/b", "a/b", "a\\b"], 70 ["a/b", "a/b", "a\\b"],
76 ["a/b/", "a/b/", "a\\b\\"], 71 ["a/b/", "a/b/", "a\\b\\"],
77 ["a%20b/c%20d", "a b/c d", "a b\\c d"], 72 ["a%20b/c%20d", "a b/c d", "a b\\c d"],
78 ["a%20b/c%20d/", "a b/c d/", "a b\\c d\\"], 73 ["a%20b/c%20d/", "a b/c d/", "a b\\c d\\"],
79
80 ["file:///absolute", "/absolute", "\\absolute"], 74 ["file:///absolute", "/absolute", "\\absolute"],
81 ["file:///absolute", "/absolute", "\\absolute"], 75 ["file:///absolute", "/absolute", "\\absolute"],
82 ["file:///a/b", "/a/b", "\\a\\b"], 76 ["file:///a/b", "/a/b", "\\a\\b"],
83 ["file:///a/b", "/a/b", "\\a\\b"], 77 ["file:///a/b", "/a/b", "\\a\\b"],
84
85 ["file://server/a/b", "//server/a/b", "\\\\server\\a\\b"], 78 ["file://server/a/b", "//server/a/b", "\\\\server\\a\\b"],
86 ["file://server/a/b/", "//server/a/b/", "\\\\server\\a\\b\\"], 79 ["file://server/a/b/", "//server/a/b/", "\\\\server\\a\\b\\"],
87
88 ["file:///C:/", "C:/", "C:\\"], 80 ["file:///C:/", "C:/", "C:\\"],
89 ["file:///C:/a/b", "C:/a/b", "C:\\a\\b"], 81 ["file:///C:/a/b", "C:/a/b", "C:\\a\\b"],
90 ["file:///C:/a/b/", "C:/a/b/", "C:\\a\\b\\"], 82 ["file:///C:/a/b/", "C:/a/b/", "C:\\a\\b\\"],
91
92 ["file:///C:/xxx/yyy", "C:\\xxx\\yyy", "C:\\xxx\\yyy"], 83 ["file:///C:/xxx/yyy", "C:\\xxx\\yyy", "C:\\xxx\\yyy"],
93 ]; 84 ];
94 85
95 for (var test in tests) { 86 for (var test in tests) {
96 Uri uri = new Uri.file(test[1], windows: true); 87 Uri uri = new Uri.file(test[1], windows: true);
97 Expect.equals(test[0], uri.toString()); 88 Expect.equals(test[0], uri.toString());
98 Expect.equals(test[2], uri.toFilePath(windows: true)); 89 Expect.equals(test[2], uri.toFilePath(windows: true));
99 bool couldBeDir = uri.path.isEmpty || uri.path.endsWith('\\'); 90 bool couldBeDir = uri.path.isEmpty || uri.path.endsWith('\\');
100 Uri dirUri = new Uri.directory(test[1], windows: true); 91 Uri dirUri = new Uri.directory(test[1], windows: true);
101 Expect.isTrue(dirUri.path.isEmpty || dirUri.path.endsWith('/')); 92 Expect.isTrue(dirUri.path.isEmpty || dirUri.path.endsWith('/'));
102 if (couldBeDir) { 93 if (couldBeDir) {
103 Expect.equals(uri, dirUri); 94 Expect.equals(uri, dirUri);
104 } 95 }
105 } 96 }
106 } 97 }
107 98
108 testFileUriWindowsWin32Namespace() { 99 testFileUriWindowsWin32Namespace() {
109 var tests = [ 100 var tests = [
110 ["\\\\?\\C:\\", "file:///C:/", "C:\\"], 101 ["\\\\?\\C:\\", "file:///C:/", "C:\\"],
111 ["\\\\?\\C:\\", "file:///C:/", "C:\\"], 102 ["\\\\?\\C:\\", "file:///C:/", "C:\\"],
112 ["\\\\?\\UNC\\server\\share\\file", 103 [
113 "file://server/share/file", 104 "\\\\?\\UNC\\server\\share\\file",
114 "\\\\server\\share\\file"], 105 "file://server/share/file",
106 "\\\\server\\share\\file"
107 ],
115 ]; 108 ];
116 109
117 for (var test in tests) { 110 for (var test in tests) {
118 Uri uri = new Uri.file(test[0], windows: true); 111 Uri uri = new Uri.file(test[0], windows: true);
119 Expect.equals(test[1], uri.toString()); 112 Expect.equals(test[1], uri.toString());
120 Expect.equals(test[2], uri.toFilePath(windows: true)); 113 Expect.equals(test[2], uri.toFilePath(windows: true));
121 } 114 }
122 115
123 Expect.throws( 116 Expect.throws(() => new Uri.file("\\\\?\\file", windows: true),
124 () => new Uri.file("\\\\?\\file", windows: true),
125 (e) => e is ArgumentError); 117 (e) => e is ArgumentError);
126 Expect.throws( 118 Expect.throws(
127 () => new Uri.file("\\\\?\\UNX\\server\\share\\file", windows: true), 119 () => new Uri.file("\\\\?\\UNX\\server\\share\\file", windows: true),
128 (e) => e is ArgumentError); 120 (e) => e is ArgumentError);
129 Expect.throws( 121 Expect.throws(() => new Uri.directory("\\\\?\\file", windows: true),
130 () => new Uri.directory("\\\\?\\file", windows: true),
131 (e) => e is ArgumentError); 122 (e) => e is ArgumentError);
132 Expect.throws( 123 Expect.throws(
133 () => new Uri.directory("\\\\?\\UNX\\server\\share\\file", windows: true), 124 () => new Uri.directory("\\\\?\\UNX\\server\\share\\file", windows: true),
134 (e) => e is ArgumentError); 125 (e) => e is ArgumentError);
135 } 126 }
136 127
137 testFileUriDriveLetter() { 128 testFileUriDriveLetter() {
138 check(String s, String nonWindows, String windows) { 129 check(String s, String nonWindows, String windows) {
139 Uri uri; 130 Uri uri;
140 uri = Uri.parse(s); 131 uri = Uri.parse(s);
141 Expect.equals(nonWindows, uri.toFilePath(windows: false)); 132 Expect.equals(nonWindows, uri.toFilePath(windows: false));
142 if (windows != null) { 133 if (windows != null) {
143 Expect.equals(windows, uri.toFilePath(windows: true)); 134 Expect.equals(windows, uri.toFilePath(windows: true));
144 } else { 135 } else {
145 Expect.throws(() => uri.toFilePath(windows: true), 136 Expect.throws(
146 (e) => e is UnsupportedError); 137 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
147 } 138 }
148 } 139 }
149 140
150 check("file:///C:", "/C:", "C:\\"); 141 check("file:///C:", "/C:", "C:\\");
151 check("file:///C:/", "/C:/", "C:\\"); 142 check("file:///C:/", "/C:/", "C:\\");
152 check("file:///C:a", "/C:a", null); 143 check("file:///C:a", "/C:a", null);
153 check("file:///C:a/", "/C:a/", null); 144 check("file:///C:a/", "/C:a/", null);
154 145
155 Expect.throws(() => new Uri.file("C:", windows: true), 146 Expect.throws(
156 (e) => e is ArgumentError); 147 () => new Uri.file("C:", windows: true), (e) => e is ArgumentError);
157 Expect.throws(() => new Uri.file("C:a", windows: true), 148 Expect.throws(
158 (e) => e is ArgumentError); 149 () => new Uri.file("C:a", windows: true), (e) => e is ArgumentError);
159 Expect.throws(() => new Uri.file("C:a\b", windows: true), 150 Expect.throws(
160 (e) => e is ArgumentError); 151 () => new Uri.file("C:a\b", windows: true), (e) => e is ArgumentError);
161 Expect.throws(() => new Uri.directory("C:", windows: true), 152 Expect.throws(
162 (e) => e is ArgumentError); 153 () => new Uri.directory("C:", windows: true), (e) => e is ArgumentError);
163 Expect.throws(() => new Uri.directory("C:a", windows: true), 154 Expect.throws(
164 (e) => e is ArgumentError); 155 () => new Uri.directory("C:a", windows: true), (e) => e is ArgumentError);
165 Expect.throws(() => new Uri.directory("C:a\b", windows: true), 156 Expect.throws(() => new Uri.directory("C:a\b", windows: true),
166 (e) => e is ArgumentError); 157 (e) => e is ArgumentError);
167 } 158 }
168 159
169 testFileUriResolve() { 160 testFileUriResolve() {
170 var tests = [ 161 var tests = [
171 ["file:///a", "/a", "", "\\a", ""], 162 ["file:///a", "/a", "", "\\a", ""],
172 ["file:///a/", "/a/", "", "\\a\\", ""], 163 ["file:///a/", "/a/", "", "\\a\\", ""],
173 ["file:///b", "/a", "b", "\\a", "b"], 164 ["file:///b", "/a", "b", "\\a", "b"],
174 ["file:///b/", "/a", "b/", "\\a", "b\\"], 165 ["file:///b/", "/a", "b/", "\\a", "b\\"],
175 ["file:///a/b", "/a/", "b", "\\a\\", "b"], 166 ["file:///a/b", "/a/", "b", "\\a\\", "b"],
176 ["file:///a/b/", "/a/", "b/", "\\a\\", "b\\"], 167 ["file:///a/b/", "/a/", "b/", "\\a\\", "b\\"],
177 ["file:///a/c/d", "/a/b", "c/d", "\\a\\b", "c\\d"], 168 ["file:///a/c/d", "/a/b", "c/d", "\\a\\b", "c\\d"],
178 ["file:///a/c/d/", "/a/b", "c/d/", "\\a\\b", "c\\d\\"], 169 ["file:///a/c/d/", "/a/b", "c/d/", "\\a\\b", "c\\d\\"],
179 ["file:///a/b/c/d", "/a/b/", "c/d", "\\a\\b\\", "c\\d"], 170 ["file:///a/b/c/d", "/a/b/", "c/d", "\\a\\b\\", "c\\d"],
180 ["file:///a/b/c/d/", "/a/b/", "c/d/", "\\a\\b\\", "c\\d\\"], 171 ["file:///a/b/c/d/", "/a/b/", "c/d/", "\\a\\b\\", "c\\d\\"],
181 ]; 172 ];
182 173
183 check(String s, String absolute, String relative, bool windows) { 174 check(String s, String absolute, String relative, bool windows) {
184 Uri absoluteUri = new Uri.file(absolute, windows: windows); 175 Uri absoluteUri = new Uri.file(absolute, windows: windows);
185 Uri relativeUri = new Uri.file(relative, windows: windows); 176 Uri relativeUri = new Uri.file(relative, windows: windows);
186 String relativeString = 177 String relativeString = windows ? relative.replaceAll("\\", "/") : relative;
187 windows ? relative.replaceAll("\\", "/") : relative;
188 Expect.equals(s, absoluteUri.resolve(relativeString).toString()); 178 Expect.equals(s, absoluteUri.resolve(relativeString).toString());
189 Expect.equals(s, absoluteUri.resolveUri(relativeUri).toString()); 179 Expect.equals(s, absoluteUri.resolveUri(relativeUri).toString());
190 } 180 }
191 181
192 for (var test in tests) { 182 for (var test in tests) {
193 check(test[0], test[1], test[2], false); 183 check(test[0], test[1], test[2], false);
194 check(test[0], test[1], test[2], true); 184 check(test[0], test[1], test[2], true);
195 check(test[0], test[1], test[4], true); 185 check(test[0], test[1], test[4], true);
196 check(test[0], test[3], test[2], true); 186 check(test[0], test[3], test[2], true);
197 check(test[0], test[3], test[4], true); 187 check(test[0], test[3], test[4], true);
198 } 188 }
199 } 189 }
200 190
201 testFileUriIllegalCharacters() { 191 testFileUriIllegalCharacters() {
202 // Slash is an invalid character in file names on both non-Windows 192 // Slash is an invalid character in file names on both non-Windows
203 // and Windows. 193 // and Windows.
204 Uri uri = Uri.parse("file:///a%2Fb"); 194 Uri uri = Uri.parse("file:///a%2Fb");
205 Expect.throws(() => uri.toFilePath(windows: false), 195 Expect.throws(
206 (e) => e is UnsupportedError); 196 () => uri.toFilePath(windows: false), (e) => e is UnsupportedError);
207 Expect.throws(() => uri.toFilePath(windows: true), 197 Expect.throws(
208 (e) => e is UnsupportedError); 198 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
209 199
210 // Illegal characters in windows file names. 200 // Illegal characters in windows file names.
211 var illegalWindowsPaths = 201 var illegalWindowsPaths = [
212 ["a<b", "a>b", "a:b", "a\"b", "a|b", "a?b", "a*b", "\\\\?\\c:\\a/b"]; 202 "a<b",
203 "a>b",
204 "a:b",
205 "a\"b",
206 "a|b",
207 "a?b",
208 "a*b",
209 "\\\\?\\c:\\a/b"
210 ];
213 211
214 for (var test in illegalWindowsPaths) { 212 for (var test in illegalWindowsPaths) {
215 Expect.throws(() => new Uri.file(test, windows: true), 213 Expect.throws(
216 (e) => e is ArgumentError); 214 () => new Uri.file(test, windows: true), (e) => e is ArgumentError);
217 Expect.throws(() => new Uri.file("\\$test", windows: true), 215 Expect.throws(() => new Uri.file("\\$test", windows: true),
218 (e) => e is ArgumentError); 216 (e) => e is ArgumentError);
219 Expect.throws(() => new Uri.directory(test, windows: true), 217 Expect.throws(() => new Uri.directory(test, windows: true),
220 (e) => e is ArgumentError); 218 (e) => e is ArgumentError);
221 Expect.throws(() => new Uri.directory("\\$test", windows: true), 219 Expect.throws(() => new Uri.directory("\\$test", windows: true),
222 (e) => e is ArgumentError); 220 (e) => e is ArgumentError);
223 221
224 // It is possible to create non-Windows URIs, but not Windows URIs. 222 // It is possible to create non-Windows URIs, but not Windows URIs.
225 Uri uri = new Uri.file(test, windows: false); 223 Uri uri = new Uri.file(test, windows: false);
226 Uri absoluteUri = new Uri.file("/$test", windows: false); 224 Uri absoluteUri = new Uri.file("/$test", windows: false);
227 Uri dirUri = new Uri.directory(test, windows: false); 225 Uri dirUri = new Uri.directory(test, windows: false);
228 Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false); 226 Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false);
229 Expect.throws(() => new Uri.file(test, windows: true), 227 Expect.throws(
230 (e) => e is ArgumentError); 228 () => new Uri.file(test, windows: true), (e) => e is ArgumentError);
231 Expect.throws(() => new Uri.file("\\$test", windows: true), 229 Expect.throws(() => new Uri.file("\\$test", windows: true),
232 (e) => e is ArgumentError); 230 (e) => e is ArgumentError);
233 Expect.throws(() => new Uri.directory(test, windows: true), 231 Expect.throws(() => new Uri.directory(test, windows: true),
234 (e) => e is ArgumentError); 232 (e) => e is ArgumentError);
235 Expect.throws(() => new Uri.directory("\\$test", windows: true), 233 Expect.throws(() => new Uri.directory("\\$test", windows: true),
236 (e) => e is ArgumentError); 234 (e) => e is ArgumentError);
237 235
238 // It is possible to extract non-Windows file path, but not 236 // It is possible to extract non-Windows file path, but not
239 // Windows file path. 237 // Windows file path.
240 Expect.equals(test, uri.toFilePath(windows: false)); 238 Expect.equals(test, uri.toFilePath(windows: false));
241 Expect.equals("/$test", absoluteUri.toFilePath(windows: false)); 239 Expect.equals("/$test", absoluteUri.toFilePath(windows: false));
242 Expect.equals("$test/", dirUri.toFilePath(windows: false)); 240 Expect.equals("$test/", dirUri.toFilePath(windows: false));
243 Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false)); 241 Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false));
244 Expect.throws(() => uri.toFilePath(windows: true), 242 Expect.throws(
245 (e) => e is UnsupportedError); 243 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
246 Expect.throws(() => absoluteUri.toFilePath(windows: true), 244 Expect.throws(() => absoluteUri.toFilePath(windows: true),
247 (e) => e is UnsupportedError); 245 (e) => e is UnsupportedError);
248 Expect.throws(() => dirUri.toFilePath(windows: true), 246 Expect.throws(
249 (e) => e is UnsupportedError); 247 () => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
250 Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true), 248 Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true),
251 (e) => e is UnsupportedError); 249 (e) => e is UnsupportedError);
252 } 250 }
253 251
254 // Backslash 252 // Backslash
255 illegalWindowsPaths = ["a\\b", "a\\b\\"]; 253 illegalWindowsPaths = ["a\\b", "a\\b\\"];
256 for (var test in illegalWindowsPaths) { 254 for (var test in illegalWindowsPaths) {
257 // It is possible to create both non-Windows URIs, and Windows URIs. 255 // It is possible to create both non-Windows URIs, and Windows URIs.
258 Uri uri = new Uri.file(test, windows: false); 256 Uri uri = new Uri.file(test, windows: false);
259 Uri absoluteUri = new Uri.file("/$test", windows: false); 257 Uri absoluteUri = new Uri.file("/$test", windows: false);
260 Uri dirUri = new Uri.directory(test, windows: false); 258 Uri dirUri = new Uri.directory(test, windows: false);
261 Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false); 259 Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false);
262 new Uri.file(test, windows: true); 260 new Uri.file(test, windows: true);
263 new Uri.file("\\$test", windows: true); 261 new Uri.file("\\$test", windows: true);
264 262
265 // It is possible to extract non-Windows file path, but not 263 // It is possible to extract non-Windows file path, but not
266 // Windows file path from the non-Windows URI (it has a backslash 264 // Windows file path from the non-Windows URI (it has a backslash
267 // in a path segment). 265 // in a path segment).
268 Expect.equals(test, uri.toFilePath(windows: false)); 266 Expect.equals(test, uri.toFilePath(windows: false));
269 Expect.equals("/$test", absoluteUri.toFilePath(windows: false)); 267 Expect.equals("/$test", absoluteUri.toFilePath(windows: false));
270 Expect.equals("$test/", dirUri.toFilePath(windows: false)); 268 Expect.equals("$test/", dirUri.toFilePath(windows: false));
271 Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false)); 269 Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false));
272 Expect.throws(() => uri.toFilePath(windows: true), 270 Expect.throws(
273 (e) => e is UnsupportedError); 271 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
274 Expect.throws(() => absoluteUri.toFilePath(windows: true), 272 Expect.throws(() => absoluteUri.toFilePath(windows: true),
275 (e) => e is UnsupportedError); 273 (e) => e is UnsupportedError);
276 Expect.throws(() => dirUri.toFilePath(windows: true), 274 Expect.throws(
277 (e) => e is UnsupportedError); 275 () => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
278 Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true), 276 Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true),
279 (e) => e is UnsupportedError); 277 (e) => e is UnsupportedError);
280 } 278 }
281 } 279 }
282 280
283 testFileUriIllegalDriveLetter() { 281 testFileUriIllegalDriveLetter() {
284 Expect.throws(() => new Uri.file("1:\\", windows: true), 282 Expect.throws(
285 (e) => e is ArgumentError); 283 () => new Uri.file("1:\\", windows: true), (e) => e is ArgumentError);
286 Expect.throws(() => new Uri.directory("1:\\", windows: true), 284 Expect.throws(() => new Uri.directory("1:\\", windows: true),
287 (e) => e is ArgumentError); 285 (e) => e is ArgumentError);
288 Uri uri = new Uri.file("1:\\", windows: false); 286 Uri uri = new Uri.file("1:\\", windows: false);
289 Uri dirUri = new Uri.directory("1:\\", windows: false); 287 Uri dirUri = new Uri.directory("1:\\", windows: false);
290 Expect.equals("1:\\", uri.toFilePath(windows: false)); 288 Expect.equals("1:\\", uri.toFilePath(windows: false));
291 Expect.equals("1:\\/", dirUri.toFilePath(windows: false)); 289 Expect.equals("1:\\/", dirUri.toFilePath(windows: false));
292 Expect.throws(() => uri.toFilePath(windows: true), 290 Expect.throws(
293 (e) => e is UnsupportedError); 291 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
294 Expect.throws(() => dirUri.toFilePath(windows: true), 292 Expect.throws(
295 (e) => e is UnsupportedError); 293 () => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
296 } 294 }
297 295
298 testAdditionalComponents() { 296 testAdditionalComponents() {
299 check(String s, {bool windowsOk: false}) { 297 check(String s, {bool windowsOk: false}) {
300 Uri uri = Uri.parse(s); 298 Uri uri = Uri.parse(s);
301 Expect.throws(() => uri.toFilePath(windows: false), 299 Expect.throws(
302 (e) => e is UnsupportedError); 300 () => uri.toFilePath(windows: false), (e) => e is UnsupportedError);
303 if (windowsOk) { 301 if (windowsOk) {
304 Expect.isTrue(uri.toFilePath(windows: true) is String); 302 Expect.isTrue(uri.toFilePath(windows: true) is String);
305 } else { 303 } else {
306 Expect.throws(() => uri.toFilePath(windows: true), 304 Expect.throws(
307 (e) => e is UnsupportedError); 305 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
308 } 306 }
309 } 307 }
310 308
311 check("file:///path?query"); 309 check("file:///path?query");
312 check("file:///path#fragment"); 310 check("file:///path#fragment");
313 check("file:///path?query#fragment"); 311 check("file:///path?query#fragment");
314 check("file://host/path", windowsOk: true); 312 check("file://host/path", windowsOk: true);
315 check("file://user:password@host/path", windowsOk: true); 313 check("file://user:password@host/path", windowsOk: true);
316 } 314 }
317 315
318 main() { 316 main() {
319 testFileUri(); 317 testFileUri();
320 testFileUriWindowsSlash(); 318 testFileUriWindowsSlash();
321 testFileUriDriveLetter(); 319 testFileUriDriveLetter();
322 testFileUriWindowsWin32Namespace(); 320 testFileUriWindowsWin32Namespace();
323 testFileUriResolve(); 321 testFileUriResolve();
324 testFileUriIllegalCharacters(); 322 testFileUriIllegalCharacters();
325 testFileUriIllegalDriveLetter(); 323 testFileUriIllegalDriveLetter();
326 testAdditionalComponents(); 324 testAdditionalComponents();
327 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698