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 |
Bob Nystrom
2013/07/18 20:45:08
And here.
| |
5 library path.test.windows_test; | 5 library path.test.windows_test; |
6 | 6 |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'package:path/path.dart' as path; | 8 import 'package:path/path.dart' as path; |
9 | 9 |
10 main() { | 10 main() { |
11 var builder = new path.Builder(style: path.Style.windows, | 11 var builder = new path.Builder(style: path.Style.windows, |
12 root: r'C:\root\path'); | 12 root: r'C:\root\path'); |
13 | 13 |
14 if (new path.Builder().style == path.Style.windows) { | 14 if (new path.Builder().style == path.Style.windows) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 expect(builder.join('', ''), ''); | 177 expect(builder.join('', ''), ''); |
178 expect(builder.join('', 'a'), 'a'); | 178 expect(builder.join('', 'a'), 'a'); |
179 expect(builder.join('a', '', 'b', '', '', '', 'c'), r'a\b\c'); | 179 expect(builder.join('a', '', 'b', '', '', '', 'c'), r'a\b\c'); |
180 expect(builder.join('a', 'b', ''), r'a\b'); | 180 expect(builder.join('a', 'b', ''), r'a\b'); |
181 }); | 181 }); |
182 | 182 |
183 test('disallows intermediate nulls', () { | 183 test('disallows intermediate nulls', () { |
184 expect(() => builder.join('a', null, 'b'), throwsArgumentError); | 184 expect(() => builder.join('a', null, 'b'), throwsArgumentError); |
185 expect(() => builder.join(null, 'a'), throwsArgumentError); | 185 expect(() => builder.join(null, 'a'), throwsArgumentError); |
186 }); | 186 }); |
187 test('misc join tests ported from Path class', () { | |
188 expect(builder.join('a/', 'b/c/'), 'a/b/c/'); | |
189 expect(builder.join(r'a\b\./c\..\\', r'd\..\.\..\\e\f\\'), | |
190 r'a\b\./c\..\\d\..\.\..\\e\f\\'); | |
191 expect(builder.join(r'a\b', r'c\..\..\..\..'), r'a\b\c\..\..\..\..'); | |
192 expect(builder.join('', ''), ''); | |
193 expect(builder.join(r'a', 'b${builder.separator}'), r'a\b\'); | |
194 }); | |
187 }); | 195 }); |
188 | 196 |
189 group('joinAll', () { | 197 group('joinAll', () { |
190 test('allows more than eight parts', () { | 198 test('allows more than eight parts', () { |
191 expect(builder.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']), | 199 expect(builder.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']), |
192 r'a\b\c\d\e\f\g\h\i'); | 200 r'a\b\c\d\e\f\g\h\i'); |
193 }); | 201 }); |
194 | 202 |
195 test('does not add separator if a part ends or begins in one', () { | 203 test('does not add separator if a part ends or begins in one', () { |
196 expect(builder.joinAll([r'a\', 'b', r'c\', 'd']), r'a\b\c\d'); | 204 expect(builder.joinAll([r'a\', 'b', r'c\', 'd']), r'a\b\c\d'); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 | 239 |
232 // TODO(nweiz): enable these once issue 7323 is fixed. | 240 // TODO(nweiz): enable these once issue 7323 is fixed. |
233 // expect(builder.split(r'\\server\foo\bar\baz'), | 241 // expect(builder.split(r'\\server\foo\bar\baz'), |
234 // equals([r'\\server\', 'foo', 'bar', 'baz'])); | 242 // equals([r'\\server\', 'foo', 'bar', 'baz'])); |
235 // expect(builder.split(r'\\server\'), equals([r'\\server\'])); | 243 // expect(builder.split(r'\\server\'), equals([r'\\server\'])); |
236 }); | 244 }); |
237 }); | 245 }); |
238 | 246 |
239 group('normalize', () { | 247 group('normalize', () { |
240 test('simple cases', () { | 248 test('simple cases', () { |
241 expect(builder.normalize(''), ''); | 249 expect(builder.normalize(''), '.'); |
242 expect(builder.normalize('.'), '.'); | 250 expect(builder.normalize('.'), '.'); |
243 expect(builder.normalize('..'), '..'); | 251 expect(builder.normalize('..'), '..'); |
244 expect(builder.normalize('a'), 'a'); | 252 expect(builder.normalize('a'), 'a'); |
253 expect(builder.normalize(r'\'), '.'); | |
254 expect(builder.normalize('/'), r'.'); | |
245 expect(builder.normalize('C:/'), r'C:\'); | 255 expect(builder.normalize('C:/'), r'C:\'); |
246 expect(builder.normalize(r'C:\'), r'C:\'); | 256 expect(builder.normalize(r'C:\'), r'C:\'); |
247 expect(builder.normalize(r'\\'), r'\\'); | 257 expect(builder.normalize(r'\\'), r'\\'); |
248 }); | 258 }); |
249 | 259 |
250 test('collapses redundant separators', () { | 260 test('collapses redundant separators', () { |
251 expect(builder.normalize(r'a\b\c'), r'a\b\c'); | 261 expect(builder.normalize(r'a\b\c'), r'a\b\c'); |
252 expect(builder.normalize(r'a\\b\\\c\\\\d'), r'a\b\c\d'); | 262 expect(builder.normalize(r'a\\b\\\c\\\\d'), r'a\b\c\d'); |
253 }); | 263 }); |
254 | 264 |
(...skipping 16 matching lines...) Expand all Loading... | |
271 expect(builder.normalize(r'..\'), '..'); | 281 expect(builder.normalize(r'..\'), '..'); |
272 expect(builder.normalize(r'..\..\..'), r'..\..\..'); | 282 expect(builder.normalize(r'..\..\..'), r'..\..\..'); |
273 expect(builder.normalize(r'../..\..\'), r'..\..\..'); | 283 expect(builder.normalize(r'../..\..\'), r'..\..\..'); |
274 // TODO(rnystrom): Is this how Python handles absolute paths on Windows? | 284 // TODO(rnystrom): Is this how Python handles absolute paths on Windows? |
275 expect(builder.normalize(r'\\..'), r'\\'); | 285 expect(builder.normalize(r'\\..'), r'\\'); |
276 expect(builder.normalize(r'\\..\..\..'), r'\\'); | 286 expect(builder.normalize(r'\\..\..\..'), r'\\'); |
277 expect(builder.normalize(r'\\..\../..\a'), r'\\a'); | 287 expect(builder.normalize(r'\\..\../..\a'), r'\\a'); |
278 expect(builder.normalize(r'c:\..'), r'c:\'); | 288 expect(builder.normalize(r'c:\..'), r'c:\'); |
279 expect(builder.normalize(r'A:/..\..\..'), r'A:\'); | 289 expect(builder.normalize(r'A:/..\..\..'), r'A:\'); |
280 expect(builder.normalize(r'b:\..\..\..\a'), r'b:\a'); | 290 expect(builder.normalize(r'b:\..\..\..\a'), r'b:\a'); |
291 expect(builder.normalize(r'b:\r\..\..\..\a\c\.\..'), r'b:\a'); | |
281 expect(builder.normalize(r'a\..'), '.'); | 292 expect(builder.normalize(r'a\..'), '.'); |
293 expect(builder.normalize(r'..\a'), r'..\a'); | |
294 expect(builder.normalize(r'c:\..\a'), r'c:\a'); | |
295 // A path starting with '\' is not an absolute path on Windows. | |
296 expect(builder.normalize(r'\..\a'), r'..\a'); | |
282 expect(builder.normalize(r'a\b\..'), 'a'); | 297 expect(builder.normalize(r'a\b\..'), 'a'); |
298 expect(builder.normalize(r'..\a\b\..'), r'..\a'); | |
283 expect(builder.normalize(r'a\..\b'), 'b'); | 299 expect(builder.normalize(r'a\..\b'), 'b'); |
284 expect(builder.normalize(r'a\.\..\b'), 'b'); | 300 expect(builder.normalize(r'a\.\..\b'), 'b'); |
285 expect(builder.normalize(r'a\b\c\..\..\d\e\..'), r'a\d'); | 301 expect(builder.normalize(r'a\b\c\..\..\d\e\..'), r'a\d'); |
286 expect(builder.normalize(r'a\b\..\..\..\..\c'), r'..\..\c'); | 302 expect(builder.normalize(r'a\b\..\..\..\..\c'), r'..\..\c'); |
303 expect(builder.normalize(r'a/b/c/../../..d/./.e/f././'), r'a\..d\.e\f.'); | |
287 }); | 304 }); |
288 | 305 |
289 test('removes trailing separators', () { | 306 test('removes trailing separators', () { |
290 expect(builder.normalize(r'.\'), '.'); | 307 expect(builder.normalize(r'.\'), '.'); |
291 expect(builder.normalize(r'.\\'), '.'); | 308 expect(builder.normalize(r'.\\'), '.'); |
292 expect(builder.normalize(r'a/'), 'a'); | 309 expect(builder.normalize(r'a/'), 'a'); |
293 expect(builder.normalize(r'a\b\'), r'a\b'); | 310 expect(builder.normalize(r'a\b\'), r'a\b'); |
294 expect(builder.normalize(r'a\b\\\'), r'a\b'); | 311 expect(builder.normalize(r'a\b\\\'), r'a\b'); |
295 }); | 312 }); |
296 | 313 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 Uri.parse('file:///C:/path/to/foo/')); | 494 Uri.parse('file:///C:/path/to/foo/')); |
478 expect(builder.toUri(r'C:\'), Uri.parse('file:///C:/')); | 495 expect(builder.toUri(r'C:\'), Uri.parse('file:///C:/')); |
479 expect(builder.toUri(r'\\hostname\'), Uri.parse('file://hostname/')); | 496 expect(builder.toUri(r'\\hostname\'), Uri.parse('file://hostname/')); |
480 expect(builder.toUri(r'foo\bar'), Uri.parse('foo/bar')); | 497 expect(builder.toUri(r'foo\bar'), Uri.parse('foo/bar')); |
481 expect(builder.toUri(r'C:\path\to\foo#bar'), | 498 expect(builder.toUri(r'C:\path\to\foo#bar'), |
482 Uri.parse('file:///C:/path/to/foo%23bar')); | 499 Uri.parse('file:///C:/path/to/foo%23bar')); |
483 expect(builder.toUri(r'\\hostname\path\to\foo#bar'), | 500 expect(builder.toUri(r'\\hostname\path\to\foo#bar'), |
484 Uri.parse('file://hostname/path/to/foo%23bar')); | 501 Uri.parse('file://hostname/path/to/foo%23bar')); |
485 }); | 502 }); |
486 } | 503 } |
OLD | NEW |