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 |
5 library path_test; | 5 library path_test; |
6 | 6 |
7 import 'dart:io' as io; | 7 import 'dart:io' as io; |
8 | 8 |
9 import '../../../../pkg/unittest/lib/unittest.dart'; | 9 import '../../../../pkg/unittest/lib/unittest.dart'; |
10 import '../../../pub/path.dart' as path; | 10 import '../../../pub/path.dart' as path; |
(...skipping 17 matching lines...) Expand all Loading... |
28 test('extension', () { | 28 test('extension', () { |
29 expect(builder.extension(''), ''); | 29 expect(builder.extension(''), ''); |
30 expect(builder.extension('foo.dart'), '.dart'); | 30 expect(builder.extension('foo.dart'), '.dart'); |
31 expect(builder.extension('foo.dart.js'), '.js'); | 31 expect(builder.extension('foo.dart.js'), '.js'); |
32 expect(builder.extension(r'a.b\c'), ''); | 32 expect(builder.extension(r'a.b\c'), ''); |
33 expect(builder.extension('a.b/c.d'), '.d'); | 33 expect(builder.extension('a.b/c.d'), '.d'); |
34 expect(builder.extension(r'~\.bashrc'), ''); | 34 expect(builder.extension(r'~\.bashrc'), ''); |
35 expect(builder.extension(r'a.b/c'), r''); | 35 expect(builder.extension(r'a.b/c'), r''); |
36 }); | 36 }); |
37 | 37 |
38 test('filename', () { | 38 test('basename', () { |
39 expect(builder.filename(r''), ''); | 39 expect(builder.basename(r''), ''); |
40 expect(builder.filename(r'a'), 'a'); | 40 expect(builder.basename(r'a'), 'a'); |
41 expect(builder.filename(r'a\b'), 'b'); | 41 expect(builder.basename(r'a\b'), 'b'); |
42 expect(builder.filename(r'a\b\c'), 'c'); | 42 expect(builder.basename(r'a\b\c'), 'c'); |
43 expect(builder.filename(r'a\b.c'), 'b.c'); | 43 expect(builder.basename(r'a\b.c'), 'b.c'); |
44 expect(builder.filename(r'a\'), ''); | 44 expect(builder.basename(r'a\'), ''); |
45 expect(builder.filename(r'a/'), ''); | 45 expect(builder.basename(r'a/'), ''); |
46 expect(builder.filename(r'a\.'), '.'); | 46 expect(builder.basename(r'a\.'), '.'); |
47 expect(builder.filename(r'a\b/c'), r'c'); | 47 expect(builder.basename(r'a\b/c'), r'c'); |
48 }); | 48 }); |
49 | 49 |
50 test('filenameWithoutExtension', () { | 50 test('basenameWithoutExtension', () { |
51 expect(builder.filenameWithoutExtension(''), ''); | 51 expect(builder.basenameWithoutExtension(''), ''); |
52 expect(builder.filenameWithoutExtension('a'), 'a'); | 52 expect(builder.basenameWithoutExtension('a'), 'a'); |
53 expect(builder.filenameWithoutExtension(r'a\b'), 'b'); | 53 expect(builder.basenameWithoutExtension(r'a\b'), 'b'); |
54 expect(builder.filenameWithoutExtension(r'a\b\c'), 'c'); | 54 expect(builder.basenameWithoutExtension(r'a\b\c'), 'c'); |
55 expect(builder.filenameWithoutExtension(r'a\b.c'), 'b'); | 55 expect(builder.basenameWithoutExtension(r'a\b.c'), 'b'); |
56 expect(builder.filenameWithoutExtension(r'a\'), ''); | 56 expect(builder.basenameWithoutExtension(r'a\'), ''); |
57 expect(builder.filenameWithoutExtension(r'a\.'), '.'); | 57 expect(builder.basenameWithoutExtension(r'a\.'), '.'); |
58 expect(builder.filenameWithoutExtension(r'a\b/c'), r'c'); | 58 expect(builder.basenameWithoutExtension(r'a\b/c'), r'c'); |
59 expect(builder.filenameWithoutExtension(r'a\.bashrc'), '.bashrc'); | 59 expect(builder.basenameWithoutExtension(r'a\.bashrc'), '.bashrc'); |
60 expect(builder.filenameWithoutExtension(r'a\b\c.d.e'), 'c.d'); | 60 expect(builder.basenameWithoutExtension(r'a\b\c.d.e'), 'c.d'); |
61 }); | 61 }); |
62 | 62 |
63 test('isAbsolute', () { | 63 test('isAbsolute', () { |
64 expect(builder.isAbsolute(''), false); | 64 expect(builder.isAbsolute(''), false); |
65 expect(builder.isAbsolute('a'), false); | 65 expect(builder.isAbsolute('a'), false); |
66 expect(builder.isAbsolute(r'a\b'), false); | 66 expect(builder.isAbsolute(r'a\b'), false); |
67 expect(builder.isAbsolute(r'\a'), false); | 67 expect(builder.isAbsolute(r'\a'), false); |
68 expect(builder.isAbsolute(r'\a\b'), false); | 68 expect(builder.isAbsolute(r'\a\b'), false); |
69 expect(builder.isAbsolute('~'), false); | 69 expect(builder.isAbsolute('~'), false); |
70 expect(builder.isAbsolute('.'), false); | 70 expect(builder.isAbsolute('.'), false); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt'); | 199 expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt'); |
200 }); | 200 }); |
201 | 201 |
202 test('given absolute path outside of root', () { | 202 test('given absolute path outside of root', () { |
203 expect(builder.relative(r'C:\a\b'), r'..\..\a\b'); | 203 expect(builder.relative(r'C:\a\b'), r'..\..\a\b'); |
204 expect(builder.relative(r'C:\root\path\a'), 'a'); | 204 expect(builder.relative(r'C:\root\path\a'), 'a'); |
205 expect(builder.relative(r'C:\root\path\a\b.txt'), r'a\b.txt'); | 205 expect(builder.relative(r'C:\root\path\a\b.txt'), r'a\b.txt'); |
206 expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt'); | 206 expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt'); |
207 }); | 207 }); |
208 | 208 |
| 209 test('given absolute path on different drive', () { |
| 210 expect(builder.relative(r'D:\a\b'), r'D:\a\b'); |
| 211 }); |
| 212 |
209 test('given relative path', () { | 213 test('given relative path', () { |
210 // The path is considered relative to the root, so it basically just | 214 // The path is considered relative to the root, so it basically just |
211 // normalizes. | 215 // normalizes. |
212 expect(builder.relative(''), '.'); | 216 expect(builder.relative(''), '.'); |
213 expect(builder.relative('.'), '.'); | 217 expect(builder.relative('.'), '.'); |
214 expect(builder.relative('a'), 'a'); | 218 expect(builder.relative('a'), 'a'); |
215 expect(builder.relative(r'a\b.txt'), r'a\b.txt'); | 219 expect(builder.relative(r'a\b.txt'), r'a\b.txt'); |
216 expect(builder.relative(r'..\a\b.txt'), r'..\a\b.txt'); | 220 expect(builder.relative(r'..\a\b.txt'), r'..\a\b.txt'); |
217 expect(builder.relative(r'a\.\b\..\c.txt'), r'a\c.txt'); | 221 expect(builder.relative(r'a\.\b\..\c.txt'), r'a\c.txt'); |
218 }); | 222 }); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 expect(builder.withoutExtension('a'), 'a'); | 286 expect(builder.withoutExtension('a'), 'a'); |
283 expect(builder.withoutExtension('.a'), '.a'); | 287 expect(builder.withoutExtension('.a'), '.a'); |
284 expect(builder.withoutExtension('a.b'), 'a'); | 288 expect(builder.withoutExtension('a.b'), 'a'); |
285 expect(builder.withoutExtension(r'a\b.c'), r'a\b'); | 289 expect(builder.withoutExtension(r'a\b.c'), r'a\b'); |
286 expect(builder.withoutExtension(r'a\b.c.d'), r'a\b.c'); | 290 expect(builder.withoutExtension(r'a\b.c.d'), r'a\b.c'); |
287 expect(builder.withoutExtension(r'a\'), r'a\'); | 291 expect(builder.withoutExtension(r'a\'), r'a\'); |
288 expect(builder.withoutExtension(r'a\b\'), r'a\b\'); | 292 expect(builder.withoutExtension(r'a\b\'), r'a\b\'); |
289 expect(builder.withoutExtension(r'a\.'), r'a\.'); | 293 expect(builder.withoutExtension(r'a\.'), r'a\.'); |
290 expect(builder.withoutExtension(r'a\.b'), r'a\.b'); | 294 expect(builder.withoutExtension(r'a\.b'), r'a\.b'); |
291 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c'); | 295 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c'); |
| 296 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d'); |
292 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c'); | 297 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c'); |
293 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c'); | 298 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c'); |
294 }); | 299 }); |
295 } | 300 } |
OLD | NEW |