| 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 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // expect(builder.split(r'\\server\'), equals([r'\\server\'])); | 209 // expect(builder.split(r'\\server\'), equals([r'\\server\'])); |
| 210 }); | 210 }); |
| 211 }); | 211 }); |
| 212 | 212 |
| 213 group('normalize', () { | 213 group('normalize', () { |
| 214 test('simple cases', () { | 214 test('simple cases', () { |
| 215 expect(builder.normalize(''), ''); | 215 expect(builder.normalize(''), ''); |
| 216 expect(builder.normalize('.'), '.'); | 216 expect(builder.normalize('.'), '.'); |
| 217 expect(builder.normalize('..'), '..'); | 217 expect(builder.normalize('..'), '..'); |
| 218 expect(builder.normalize('a'), 'a'); | 218 expect(builder.normalize('a'), 'a'); |
| 219 expect(builder.normalize('C:/'), r'C:/'); | 219 expect(builder.normalize('C:/'), r'C:\'); |
| 220 expect(builder.normalize(r'C:\'), r'C:\'); | 220 expect(builder.normalize(r'C:\'), r'C:\'); |
| 221 expect(builder.normalize(r'\\'), r'\\'); | 221 expect(builder.normalize(r'\\'), r'\\'); |
| 222 }); | 222 }); |
| 223 | 223 |
| 224 test('collapses redundant separators', () { | 224 test('collapses redundant separators', () { |
| 225 expect(builder.normalize(r'a\b\c'), r'a\b\c'); | 225 expect(builder.normalize(r'a\b\c'), r'a\b\c'); |
| 226 expect(builder.normalize(r'a\\b\\\c\\\\d'), r'a\b\c\d'); | 226 expect(builder.normalize(r'a\\b\\\c\\\\d'), r'a\b\c\d'); |
| 227 }); | 227 }); |
| 228 | 228 |
| 229 test('eliminates "." parts', () { | 229 test('eliminates "." parts', () { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 243 test('eliminates ".." parts', () { | 243 test('eliminates ".." parts', () { |
| 244 expect(builder.normalize('..'), '..'); | 244 expect(builder.normalize('..'), '..'); |
| 245 expect(builder.normalize(r'..\'), '..'); | 245 expect(builder.normalize(r'..\'), '..'); |
| 246 expect(builder.normalize(r'..\..\..'), r'..\..\..'); | 246 expect(builder.normalize(r'..\..\..'), r'..\..\..'); |
| 247 expect(builder.normalize(r'../..\..\'), r'..\..\..'); | 247 expect(builder.normalize(r'../..\..\'), r'..\..\..'); |
| 248 // TODO(rnystrom): Is this how Python handles absolute paths on Windows? | 248 // TODO(rnystrom): Is this how Python handles absolute paths on Windows? |
| 249 expect(builder.normalize(r'\\..'), r'\\'); | 249 expect(builder.normalize(r'\\..'), r'\\'); |
| 250 expect(builder.normalize(r'\\..\..\..'), r'\\'); | 250 expect(builder.normalize(r'\\..\..\..'), r'\\'); |
| 251 expect(builder.normalize(r'\\..\../..\a'), r'\\a'); | 251 expect(builder.normalize(r'\\..\../..\a'), r'\\a'); |
| 252 expect(builder.normalize(r'c:\..'), r'c:\'); | 252 expect(builder.normalize(r'c:\..'), r'c:\'); |
| 253 expect(builder.normalize(r'A:/..\..\..'), r'A:/'); | 253 expect(builder.normalize(r'A:/..\..\..'), r'A:\'); |
| 254 expect(builder.normalize(r'b:\..\..\..\a'), r'b:\a'); | 254 expect(builder.normalize(r'b:\..\..\..\a'), r'b:\a'); |
| 255 expect(builder.normalize(r'a\..'), '.'); | 255 expect(builder.normalize(r'a\..'), '.'); |
| 256 expect(builder.normalize(r'a\b\..'), 'a'); | 256 expect(builder.normalize(r'a\b\..'), 'a'); |
| 257 expect(builder.normalize(r'a\..\b'), 'b'); | 257 expect(builder.normalize(r'a\..\b'), 'b'); |
| 258 expect(builder.normalize(r'a\.\..\b'), 'b'); | 258 expect(builder.normalize(r'a\.\..\b'), 'b'); |
| 259 expect(builder.normalize(r'a\b\c\..\..\d\e\..'), r'a\d'); | 259 expect(builder.normalize(r'a\b\c\..\..\d\e\..'), r'a\d'); |
| 260 expect(builder.normalize(r'a\b\..\..\..\..\c'), r'..\..\c'); | 260 expect(builder.normalize(r'a\b\..\..\..\..\c'), r'..\..\c'); |
| 261 }); | 261 }); |
| 262 | 262 |
| 263 test('removes trailing separators', () { | 263 test('removes trailing separators', () { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 275 | 275 |
| 276 group('relative', () { | 276 group('relative', () { |
| 277 group('from absolute root', () { | 277 group('from absolute root', () { |
| 278 test('given absolute path in root', () { | 278 test('given absolute path in root', () { |
| 279 expect(builder.relative(r'C:\'), r'..\..'); | 279 expect(builder.relative(r'C:\'), r'..\..'); |
| 280 expect(builder.relative(r'C:\root'), '..'); | 280 expect(builder.relative(r'C:\root'), '..'); |
| 281 expect(builder.relative(r'C:\root\path'), '.'); | 281 expect(builder.relative(r'C:\root\path'), '.'); |
| 282 expect(builder.relative(r'C:\root\path\a'), 'a'); | 282 expect(builder.relative(r'C:\root\path\a'), 'a'); |
| 283 expect(builder.relative(r'C:\root\path\a\b.txt'), r'a\b.txt'); | 283 expect(builder.relative(r'C:\root\path\a\b.txt'), r'a\b.txt'); |
| 284 expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt'); | 284 expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt'); |
| 285 expect(builder.relative(r'C:/'), r'..\..'); |
| 286 expect(builder.relative(r'C:/root'), '..'); |
| 287 expect(builder.relative(r'c:\'), r'..\..'); |
| 288 expect(builder.relative(r'c:\root'), '..'); |
| 285 }); | 289 }); |
| 286 | 290 |
| 287 test('given absolute path outside of root', () { | 291 test('given absolute path outside of root', () { |
| 288 expect(builder.relative(r'C:\a\b'), r'..\..\a\b'); | 292 expect(builder.relative(r'C:\a\b'), r'..\..\a\b'); |
| 289 expect(builder.relative(r'C:\root\path\a'), 'a'); | 293 expect(builder.relative(r'C:\root\path\a'), 'a'); |
| 290 expect(builder.relative(r'C:\root\path\a\b.txt'), r'a\b.txt'); | 294 expect(builder.relative(r'C:\root\path\a\b.txt'), r'a\b.txt'); |
| 291 expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt'); | 295 expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt'); |
| 296 expect(builder.relative(r'C:/a/b'), r'..\..\a\b'); |
| 297 expect(builder.relative(r'C:/root/path/a'), 'a'); |
| 298 expect(builder.relative(r'c:\a\b'), r'..\..\a\b'); |
| 299 expect(builder.relative(r'c:\root\path\a'), 'a'); |
| 292 }); | 300 }); |
| 293 | 301 |
| 294 test('given absolute path on different drive', () { | 302 test('given absolute path on different drive', () { |
| 295 expect(builder.relative(r'D:\a\b'), r'D:\a\b'); | 303 expect(builder.relative(r'D:\a\b'), r'D:\a\b'); |
| 296 }); | 304 }); |
| 297 | 305 |
| 298 test('given relative path', () { | 306 test('given relative path', () { |
| 299 // The path is considered relative to the root, so it basically just | 307 // The path is considered relative to the root, so it basically just |
| 300 // normalizes. | 308 // normalizes. |
| 301 expect(builder.relative(''), '.'); | 309 expect(builder.relative(''), '.'); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 expect(builder.withoutExtension(r'a\.'), r'a\.'); | 405 expect(builder.withoutExtension(r'a\.'), r'a\.'); |
| 398 expect(builder.withoutExtension(r'a\.b'), r'a\.b'); | 406 expect(builder.withoutExtension(r'a\.b'), r'a\.b'); |
| 399 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c'); | 407 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c'); |
| 400 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d'); | 408 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d'); |
| 401 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c'); | 409 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c'); |
| 402 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c'); | 410 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c'); |
| 403 expect(builder.withoutExtension(r'a.b/c'), r'a.b/c'); | 411 expect(builder.withoutExtension(r'a.b/c'), r'a.b/c'); |
| 404 expect(builder.withoutExtension(r'a\b.c\'), r'a\b\'); | 412 expect(builder.withoutExtension(r'a\b.c\'), r'a\b\'); |
| 405 }); | 413 }); |
| 406 } | 414 } |
| OLD | NEW |