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

Side by Side Diff: tests/corelib_strong/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 ]; 83 ];
92 84
93 for (var test in tests) { 85 for (var test in tests) {
94 Uri uri = new Uri.file(test[1], windows: true); 86 Uri uri = new Uri.file(test[1], windows: true);
95 Expect.equals(test[0], uri.toString()); 87 Expect.equals(test[0], uri.toString());
96 Expect.equals(test[2], uri.toFilePath(windows: true)); 88 Expect.equals(test[2], uri.toFilePath(windows: true));
97 bool couldBeDir = uri.path.isEmpty || uri.path.endsWith('\\'); 89 bool couldBeDir = uri.path.isEmpty || uri.path.endsWith('\\');
98 Uri dirUri = new Uri.directory(test[1], windows: true); 90 Uri dirUri = new Uri.directory(test[1], windows: true);
99 Expect.isTrue(dirUri.path.isEmpty || dirUri.path.endsWith('/')); 91 Expect.isTrue(dirUri.path.isEmpty || dirUri.path.endsWith('/'));
100 if (couldBeDir) { 92 if (couldBeDir) {
101 Expect.equals(uri, dirUri); 93 Expect.equals(uri, dirUri);
102 } 94 }
103 } 95 }
104 } 96 }
105 97
106 testFileUriWindowsWin32Namespace() { 98 testFileUriWindowsWin32Namespace() {
107 var tests = [ 99 var tests = [
108 ["\\\\?\\C:\\", "file:///C:/", "C:\\"], 100 ["\\\\?\\C:\\", "file:///C:/", "C:\\"],
109 ["\\\\?\\C:\\", "file:///C:/", "C:\\"], 101 ["\\\\?\\C:\\", "file:///C:/", "C:\\"],
110 ["\\\\?\\UNC\\server\\share\\file", 102 [
111 "file://server/share/file", 103 "\\\\?\\UNC\\server\\share\\file",
112 "\\\\server\\share\\file"], 104 "file://server/share/file",
105 "\\\\server\\share\\file"
106 ],
113 ]; 107 ];
114 108
115 for (var test in tests) { 109 for (var test in tests) {
116 Uri uri = new Uri.file(test[0], windows: true); 110 Uri uri = new Uri.file(test[0], windows: true);
117 Expect.equals(test[1], uri.toString()); 111 Expect.equals(test[1], uri.toString());
118 Expect.equals(test[2], uri.toFilePath(windows: true)); 112 Expect.equals(test[2], uri.toFilePath(windows: true));
119 } 113 }
120 114
121 Expect.throws( 115 Expect.throws(() => new Uri.file("\\\\?\\file", windows: true),
122 () => new Uri.file("\\\\?\\file", windows: true),
123 (e) => e is ArgumentError); 116 (e) => e is ArgumentError);
124 Expect.throws( 117 Expect.throws(
125 () => new Uri.file("\\\\?\\UNX\\server\\share\\file", windows: true), 118 () => new Uri.file("\\\\?\\UNX\\server\\share\\file", windows: true),
126 (e) => e is ArgumentError); 119 (e) => e is ArgumentError);
127 Expect.throws( 120 Expect.throws(() => new Uri.directory("\\\\?\\file", windows: true),
128 () => new Uri.directory("\\\\?\\file", windows: true),
129 (e) => e is ArgumentError); 121 (e) => e is ArgumentError);
130 Expect.throws( 122 Expect.throws(
131 () => new Uri.directory("\\\\?\\UNX\\server\\share\\file", windows: true), 123 () => new Uri.directory("\\\\?\\UNX\\server\\share\\file", windows: true),
132 (e) => e is ArgumentError); 124 (e) => e is ArgumentError);
133 } 125 }
134 126
135 testFileUriDriveLetter() { 127 testFileUriDriveLetter() {
136 check(String s, String nonWindows, String windows) { 128 check(String s, String nonWindows, String windows) {
137 Uri uri; 129 Uri uri;
138 uri = Uri.parse(s); 130 uri = Uri.parse(s);
139 Expect.equals(nonWindows, uri.toFilePath(windows: false)); 131 Expect.equals(nonWindows, uri.toFilePath(windows: false));
140 if (windows != null) { 132 if (windows != null) {
141 Expect.equals(windows, uri.toFilePath(windows: true)); 133 Expect.equals(windows, uri.toFilePath(windows: true));
142 } else { 134 } else {
143 Expect.throws(() => uri.toFilePath(windows: true), 135 Expect.throws(
144 (e) => e is UnsupportedError); 136 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
145 } 137 }
146 } 138 }
147 139
148 check("file:///C:", "/C:", "C:\\"); 140 check("file:///C:", "/C:", "C:\\");
149 check("file:///C:/", "/C:/", "C:\\"); 141 check("file:///C:/", "/C:/", "C:\\");
150 check("file:///C:a", "/C:a", null); 142 check("file:///C:a", "/C:a", null);
151 check("file:///C:a/", "/C:a/", null); 143 check("file:///C:a/", "/C:a/", null);
152 144
153 Expect.throws(() => new Uri.file("C:", windows: true), 145 Expect.throws(
154 (e) => e is ArgumentError); 146 () => new Uri.file("C:", windows: true), (e) => e is ArgumentError);
155 Expect.throws(() => new Uri.file("C:a", windows: true), 147 Expect.throws(
156 (e) => e is ArgumentError); 148 () => new Uri.file("C:a", windows: true), (e) => e is ArgumentError);
157 Expect.throws(() => new Uri.file("C:a\b", windows: true), 149 Expect.throws(
158 (e) => e is ArgumentError); 150 () => new Uri.file("C:a\b", windows: true), (e) => e is ArgumentError);
159 Expect.throws(() => new Uri.directory("C:", windows: true), 151 Expect.throws(
160 (e) => e is ArgumentError); 152 () => new Uri.directory("C:", windows: true), (e) => e is ArgumentError);
161 Expect.throws(() => new Uri.directory("C:a", windows: true), 153 Expect.throws(
162 (e) => e is ArgumentError); 154 () => new Uri.directory("C:a", windows: true), (e) => e is ArgumentError);
163 Expect.throws(() => new Uri.directory("C:a\b", windows: true), 155 Expect.throws(() => new Uri.directory("C:a\b", windows: true),
164 (e) => e is ArgumentError); 156 (e) => e is ArgumentError);
165 } 157 }
166 158
167 testFileUriResolve() { 159 testFileUriResolve() {
168 var tests = [ 160 var tests = [
169 ["file:///a", "/a", "", "\\a", ""], 161 ["file:///a", "/a", "", "\\a", ""],
170 ["file:///a/", "/a/", "", "\\a\\", ""], 162 ["file:///a/", "/a/", "", "\\a\\", ""],
171 ["file:///b", "/a", "b", "\\a", "b"], 163 ["file:///b", "/a", "b", "\\a", "b"],
172 ["file:///b/", "/a", "b/", "\\a", "b\\"], 164 ["file:///b/", "/a", "b/", "\\a", "b\\"],
173 ["file:///a/b", "/a/", "b", "\\a\\", "b"], 165 ["file:///a/b", "/a/", "b", "\\a\\", "b"],
174 ["file:///a/b/", "/a/", "b/", "\\a\\", "b\\"], 166 ["file:///a/b/", "/a/", "b/", "\\a\\", "b\\"],
175 ["file:///a/c/d", "/a/b", "c/d", "\\a\\b", "c\\d"], 167 ["file:///a/c/d", "/a/b", "c/d", "\\a\\b", "c\\d"],
176 ["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\\"],
177 ["file:///a/b/c/d", "/a/b/", "c/d", "\\a\\b\\", "c\\d"], 169 ["file:///a/b/c/d", "/a/b/", "c/d", "\\a\\b\\", "c\\d"],
178 ["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\\"],
179 ]; 171 ];
180 172
181 check(String s, String absolute, String relative, bool windows) { 173 check(String s, String absolute, String relative, bool windows) {
182 Uri absoluteUri = new Uri.file(absolute, windows: windows); 174 Uri absoluteUri = new Uri.file(absolute, windows: windows);
183 Uri relativeUri = new Uri.file(relative, windows: windows); 175 Uri relativeUri = new Uri.file(relative, windows: windows);
184 String relativeString = 176 String relativeString = windows ? relative.replaceAll("\\", "/") : relative;
185 windows ? relative.replaceAll("\\", "/") : relative;
186 Expect.equals(s, absoluteUri.resolve(relativeString).toString()); 177 Expect.equals(s, absoluteUri.resolve(relativeString).toString());
187 Expect.equals(s, absoluteUri.resolveUri(relativeUri).toString()); 178 Expect.equals(s, absoluteUri.resolveUri(relativeUri).toString());
188 } 179 }
189 180
190 for (var test in tests) { 181 for (var test in tests) {
191 check(test[0], test[1], test[2], false); 182 check(test[0], test[1], test[2], false);
192 check(test[0], test[1], test[2], true); 183 check(test[0], test[1], test[2], true);
193 check(test[0], test[1], test[4], true); 184 check(test[0], test[1], test[4], true);
194 check(test[0], test[3], test[2], true); 185 check(test[0], test[3], test[2], true);
195 check(test[0], test[3], test[4], true); 186 check(test[0], test[3], test[4], true);
196 } 187 }
197 } 188 }
198 189
199 testFileUriIllegalCharacters() { 190 testFileUriIllegalCharacters() {
200 // Slash is an invalid character in file names on both non-Windows 191 // Slash is an invalid character in file names on both non-Windows
201 // and Windows. 192 // and Windows.
202 Uri uri = Uri.parse("file:///a%2Fb"); 193 Uri uri = Uri.parse("file:///a%2Fb");
203 Expect.throws(() => uri.toFilePath(windows: false), 194 Expect.throws(
204 (e) => e is UnsupportedError); 195 () => uri.toFilePath(windows: false), (e) => e is UnsupportedError);
205 Expect.throws(() => uri.toFilePath(windows: true), 196 Expect.throws(
206 (e) => e is UnsupportedError); 197 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
207 198
208 // Illegal characters in windows file names. 199 // Illegal characters in windows file names.
209 var illegalWindowsPaths = 200 var illegalWindowsPaths = [
210 ["a<b", "a>b", "a:b", "a\"b", "a|b", "a?b", "a*b", "\\\\?\\c:\\a/b"]; 201 "a<b",
202 "a>b",
203 "a:b",
204 "a\"b",
205 "a|b",
206 "a?b",
207 "a*b",
208 "\\\\?\\c:\\a/b"
209 ];
211 210
212 for (var test in illegalWindowsPaths) { 211 for (var test in illegalWindowsPaths) {
213 Expect.throws(() => new Uri.file(test, windows: true), 212 Expect.throws(
214 (e) => e is ArgumentError); 213 () => new Uri.file(test, windows: true), (e) => e is ArgumentError);
215 Expect.throws(() => new Uri.file("\\$test", windows: true), 214 Expect.throws(() => new Uri.file("\\$test", windows: true),
216 (e) => e is ArgumentError); 215 (e) => e is ArgumentError);
217 Expect.throws(() => new Uri.directory(test, windows: true), 216 Expect.throws(() => new Uri.directory(test, windows: true),
218 (e) => e is ArgumentError); 217 (e) => e is ArgumentError);
219 Expect.throws(() => new Uri.directory("\\$test", windows: true), 218 Expect.throws(() => new Uri.directory("\\$test", windows: true),
220 (e) => e is ArgumentError); 219 (e) => e is ArgumentError);
221 220
222 // It is possible to create non-Windows URIs, but not Windows URIs. 221 // It is possible to create non-Windows URIs, but not Windows URIs.
223 Uri uri = new Uri.file(test, windows: false); 222 Uri uri = new Uri.file(test, windows: false);
224 Uri absoluteUri = new Uri.file("/$test", windows: false); 223 Uri absoluteUri = new Uri.file("/$test", windows: false);
225 Uri dirUri = new Uri.directory(test, windows: false); 224 Uri dirUri = new Uri.directory(test, windows: false);
226 Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false); 225 Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false);
227 Expect.throws(() => new Uri.file(test, windows: true), 226 Expect.throws(
228 (e) => e is ArgumentError); 227 () => new Uri.file(test, windows: true), (e) => e is ArgumentError);
229 Expect.throws(() => new Uri.file("\\$test", windows: true), 228 Expect.throws(() => new Uri.file("\\$test", windows: true),
230 (e) => e is ArgumentError); 229 (e) => e is ArgumentError);
231 Expect.throws(() => new Uri.directory(test, windows: true), 230 Expect.throws(() => new Uri.directory(test, windows: true),
232 (e) => e is ArgumentError); 231 (e) => e is ArgumentError);
233 Expect.throws(() => new Uri.directory("\\$test", windows: true), 232 Expect.throws(() => new Uri.directory("\\$test", windows: true),
234 (e) => e is ArgumentError); 233 (e) => e is ArgumentError);
235 234
236 // It is possible to extract non-Windows file path, but not 235 // It is possible to extract non-Windows file path, but not
237 // Windows file path. 236 // Windows file path.
238 Expect.equals(test, uri.toFilePath(windows: false)); 237 Expect.equals(test, uri.toFilePath(windows: false));
239 Expect.equals("/$test", absoluteUri.toFilePath(windows: false)); 238 Expect.equals("/$test", absoluteUri.toFilePath(windows: false));
240 Expect.equals("$test/", dirUri.toFilePath(windows: false)); 239 Expect.equals("$test/", dirUri.toFilePath(windows: false));
241 Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false)); 240 Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false));
242 Expect.throws(() => uri.toFilePath(windows: true), 241 Expect.throws(
243 (e) => e is UnsupportedError); 242 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
244 Expect.throws(() => absoluteUri.toFilePath(windows: true), 243 Expect.throws(() => absoluteUri.toFilePath(windows: true),
245 (e) => e is UnsupportedError); 244 (e) => e is UnsupportedError);
246 Expect.throws(() => dirUri.toFilePath(windows: true), 245 Expect.throws(
247 (e) => e is UnsupportedError); 246 () => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
248 Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true), 247 Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true),
249 (e) => e is UnsupportedError); 248 (e) => e is UnsupportedError);
250 } 249 }
251 250
252 // Backslash 251 // Backslash
253 illegalWindowsPaths = ["a\\b", "a\\b\\"]; 252 illegalWindowsPaths = ["a\\b", "a\\b\\"];
254 for (var test in illegalWindowsPaths) { 253 for (var test in illegalWindowsPaths) {
255 // It is possible to create both non-Windows URIs, and Windows URIs. 254 // It is possible to create both non-Windows URIs, and Windows URIs.
256 Uri uri = new Uri.file(test, windows: false); 255 Uri uri = new Uri.file(test, windows: false);
257 Uri absoluteUri = new Uri.file("/$test", windows: false); 256 Uri absoluteUri = new Uri.file("/$test", windows: false);
258 Uri dirUri = new Uri.directory(test, windows: false); 257 Uri dirUri = new Uri.directory(test, windows: false);
259 Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false); 258 Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false);
260 new Uri.file(test, windows: true); 259 new Uri.file(test, windows: true);
261 new Uri.file("\\$test", windows: true); 260 new Uri.file("\\$test", windows: true);
262 261
263 // It is possible to extract non-Windows file path, but not 262 // It is possible to extract non-Windows file path, but not
264 // Windows file path from the non-Windows URI (it has a backslash 263 // Windows file path from the non-Windows URI (it has a backslash
265 // in a path segment). 264 // in a path segment).
266 Expect.equals(test, uri.toFilePath(windows: false)); 265 Expect.equals(test, uri.toFilePath(windows: false));
267 Expect.equals("/$test", absoluteUri.toFilePath(windows: false)); 266 Expect.equals("/$test", absoluteUri.toFilePath(windows: false));
268 Expect.equals("$test/", dirUri.toFilePath(windows: false)); 267 Expect.equals("$test/", dirUri.toFilePath(windows: false));
269 Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false)); 268 Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false));
270 Expect.throws(() => uri.toFilePath(windows: true), 269 Expect.throws(
271 (e) => e is UnsupportedError); 270 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
272 Expect.throws(() => absoluteUri.toFilePath(windows: true), 271 Expect.throws(() => absoluteUri.toFilePath(windows: true),
273 (e) => e is UnsupportedError); 272 (e) => e is UnsupportedError);
274 Expect.throws(() => dirUri.toFilePath(windows: true), 273 Expect.throws(
275 (e) => e is UnsupportedError); 274 () => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
276 Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true), 275 Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true),
277 (e) => e is UnsupportedError); 276 (e) => e is UnsupportedError);
278 } 277 }
279 } 278 }
280 279
281 testFileUriIllegalDriveLetter() { 280 testFileUriIllegalDriveLetter() {
282 Expect.throws(() => new Uri.file("1:\\", windows: true), 281 Expect.throws(
283 (e) => e is ArgumentError); 282 () => new Uri.file("1:\\", windows: true), (e) => e is ArgumentError);
284 Expect.throws(() => new Uri.directory("1:\\", windows: true), 283 Expect.throws(() => new Uri.directory("1:\\", windows: true),
285 (e) => e is ArgumentError); 284 (e) => e is ArgumentError);
286 Uri uri = new Uri.file("1:\\", windows: false); 285 Uri uri = new Uri.file("1:\\", windows: false);
287 Uri dirUri = new Uri.directory("1:\\", windows: false); 286 Uri dirUri = new Uri.directory("1:\\", windows: false);
288 Expect.equals("1:\\", uri.toFilePath(windows: false)); 287 Expect.equals("1:\\", uri.toFilePath(windows: false));
289 Expect.equals("1:\\/", dirUri.toFilePath(windows: false)); 288 Expect.equals("1:\\/", dirUri.toFilePath(windows: false));
290 Expect.throws(() => uri.toFilePath(windows: true), 289 Expect.throws(
291 (e) => e is UnsupportedError); 290 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
292 Expect.throws(() => dirUri.toFilePath(windows: true), 291 Expect.throws(
293 (e) => e is UnsupportedError); 292 () => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
294 } 293 }
295 294
296 testAdditionalComponents() { 295 testAdditionalComponents() {
297 check(String s, {bool windowsOk: false}) { 296 check(String s, {bool windowsOk: false}) {
298 Uri uri = Uri.parse(s); 297 Uri uri = Uri.parse(s);
299 Expect.throws(() => uri.toFilePath(windows: false), 298 Expect.throws(
300 (e) => e is UnsupportedError); 299 () => uri.toFilePath(windows: false), (e) => e is UnsupportedError);
301 if (windowsOk) { 300 if (windowsOk) {
302 Expect.isTrue(uri.toFilePath(windows: true) is String); 301 Expect.isTrue(uri.toFilePath(windows: true) is String);
303 } else { 302 } else {
304 Expect.throws(() => uri.toFilePath(windows: true), 303 Expect.throws(
305 (e) => e is UnsupportedError); 304 () => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
306 } 305 }
307 } 306 }
308 307
309 check("file:///path?query"); 308 check("file:///path?query");
310 check("file:///path#fragment"); 309 check("file:///path#fragment");
311 check("file:///path?query#fragment"); 310 check("file:///path?query#fragment");
312 check("file://host/path", windowsOk: true); 311 check("file://host/path", windowsOk: true);
313 check("file://user:password@host/path", windowsOk: true); 312 check("file://user:password@host/path", windowsOk: true);
314 } 313 }
315 314
316 main() { 315 main() {
317 testFileUri(); 316 testFileUri();
318 testFileUriWindowsSlash(); 317 testFileUriWindowsSlash();
319 testFileUriDriveLetter(); 318 testFileUriDriveLetter();
320 testFileUriWindowsWin32Namespace(); 319 testFileUriWindowsWin32Namespace();
321 testFileUriResolve(); 320 testFileUriResolve();
322 testFileUriIllegalCharacters(); 321 testFileUriIllegalCharacters();
323 testFileUriIllegalDriveLetter(); 322 testFileUriIllegalDriveLetter();
324 testAdditionalComponents(); 323 testAdditionalComponents();
325 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698