| 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 import 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
| 6 import 'package:path/path.dart' as path; | 6 import 'package:path/path.dart' as path; |
| 7 | 7 |
| 8 main() { | 8 main() { |
| 9 var builder = new path.Builder(style: path.Style.url, | 9 var builder = new path.Builder(style: path.Style.url, |
| 10 root: 'http://dartlang.org/root/path'); | 10 root: 'http://dartlang.org/root/path'); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 expect(builder.basename('http://dartlang.org/'), 'http://dartlang.org'); | 82 expect(builder.basename('http://dartlang.org/'), 'http://dartlang.org'); |
| 83 expect(builder.basename('http://dartlang.org'), 'http://dartlang.org'); | 83 expect(builder.basename('http://dartlang.org'), 'http://dartlang.org'); |
| 84 expect(builder.basename('file:///'), 'file://'); | 84 expect(builder.basename('file:///'), 'file://'); |
| 85 expect(builder.basename('file://'), 'file://'); | 85 expect(builder.basename('file://'), 'file://'); |
| 86 expect(builder.basename('/'), '/'); | 86 expect(builder.basename('/'), '/'); |
| 87 expect(builder.basename('a/b/'), 'b'); | 87 expect(builder.basename('a/b/'), 'b'); |
| 88 expect(builder.basename(r'a/b\c'), r'b\c'); | 88 expect(builder.basename(r'a/b\c'), r'b\c'); |
| 89 expect(builder.basename('a//'), 'a'); | 89 expect(builder.basename('a//'), 'a'); |
| 90 expect(builder.basename('a/b//'), 'b'); | 90 expect(builder.basename('a/b//'), 'b'); |
| 91 expect(builder.basename('a//b'), 'b'); | 91 expect(builder.basename('a//b'), 'b'); |
| 92 expect(builder.basename('a b/c d.e f'), 'c d.e f'); |
| 92 }); | 93 }); |
| 93 | 94 |
| 94 test('basenameWithoutExtension', () { | 95 test('basenameWithoutExtension', () { |
| 95 expect(builder.basenameWithoutExtension(''), ''); | 96 expect(builder.basenameWithoutExtension(''), ''); |
| 97 expect(builder.basenameWithoutExtension('.'), '.'); |
| 98 expect(builder.basenameWithoutExtension('..'), '..'); |
| 96 expect(builder.basenameWithoutExtension('a'), 'a'); | 99 expect(builder.basenameWithoutExtension('a'), 'a'); |
| 97 expect(builder.basenameWithoutExtension('a/b'), 'b'); | 100 expect(builder.basenameWithoutExtension('a/b'), 'b'); |
| 98 expect(builder.basenameWithoutExtension('a/b/c'), 'c'); | 101 expect(builder.basenameWithoutExtension('a/b/c'), 'c'); |
| 99 expect(builder.basenameWithoutExtension('a/b.c'), 'b'); | 102 expect(builder.basenameWithoutExtension('a/b.c'), 'b'); |
| 100 expect(builder.basenameWithoutExtension('a/'), 'a'); | 103 expect(builder.basenameWithoutExtension('a/'), 'a'); |
| 101 expect(builder.basenameWithoutExtension('a/.'), '.'); | 104 expect(builder.basenameWithoutExtension('a/.'), '.'); |
| 102 expect(builder.basenameWithoutExtension(r'a/b\c'), r'b\c'); | 105 expect(builder.basenameWithoutExtension(r'a/b\c'), r'b\c'); |
| 103 expect(builder.basenameWithoutExtension('a/.bashrc'), '.bashrc'); | 106 expect(builder.basenameWithoutExtension('a/.bashrc'), '.bashrc'); |
| 104 expect(builder.basenameWithoutExtension('a/b/c.d.e'), 'c.d'); | 107 expect(builder.basenameWithoutExtension('a/b/c.d.e'), 'c.d'); |
| 105 expect(builder.basenameWithoutExtension('a//'), 'a'); | 108 expect(builder.basenameWithoutExtension('a//'), 'a'); |
| 106 expect(builder.basenameWithoutExtension('a/b//'), 'b'); | 109 expect(builder.basenameWithoutExtension('a/b//'), 'b'); |
| 107 expect(builder.basenameWithoutExtension('a//b'), 'b'); | 110 expect(builder.basenameWithoutExtension('a//b'), 'b'); |
| 108 expect(builder.basenameWithoutExtension('a/b.c/'), 'b'); | 111 expect(builder.basenameWithoutExtension('a/b.c/'), 'b'); |
| 109 expect(builder.basenameWithoutExtension('a/b.c//'), 'b'); | 112 expect(builder.basenameWithoutExtension('a/b.c//'), 'b'); |
| 113 expect(builder.basenameWithoutExtension('a/b c.d e.f g'), 'b c.d e'); |
| 110 }); | 114 }); |
| 111 | 115 |
| 112 test('isAbsolute', () { | 116 test('isAbsolute', () { |
| 113 expect(builder.isAbsolute(''), false); | 117 expect(builder.isAbsolute(''), false); |
| 114 expect(builder.isAbsolute('a'), false); | 118 expect(builder.isAbsolute('a'), false); |
| 115 expect(builder.isAbsolute('a/b'), false); | 119 expect(builder.isAbsolute('a/b'), false); |
| 116 expect(builder.isAbsolute('http://dartlang.org/a'), true); | 120 expect(builder.isAbsolute('http://dartlang.org/a'), true); |
| 117 expect(builder.isAbsolute('file:///a'), true); | 121 expect(builder.isAbsolute('file:///a'), true); |
| 118 expect(builder.isAbsolute('/a'), true); | 122 expect(builder.isAbsolute('/a'), true); |
| 119 expect(builder.isAbsolute('http://dartlang.org/a/b'), true); | 123 expect(builder.isAbsolute('http://dartlang.org/a/b'), true); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 expect(builder.join('', ''), ''); | 232 expect(builder.join('', ''), ''); |
| 229 expect(builder.join('', 'a'), 'a'); | 233 expect(builder.join('', 'a'), 'a'); |
| 230 expect(builder.join('a', '', 'b', '', '', '', 'c'), 'a/b/c'); | 234 expect(builder.join('a', '', 'b', '', '', '', 'c'), 'a/b/c'); |
| 231 expect(builder.join('a', 'b', ''), 'a/b'); | 235 expect(builder.join('a', 'b', ''), 'a/b'); |
| 232 }); | 236 }); |
| 233 | 237 |
| 234 test('disallows intermediate nulls', () { | 238 test('disallows intermediate nulls', () { |
| 235 expect(() => builder.join('a', null, 'b'), throwsArgumentError); | 239 expect(() => builder.join('a', null, 'b'), throwsArgumentError); |
| 236 expect(() => builder.join(null, 'a'), throwsArgumentError); | 240 expect(() => builder.join(null, 'a'), throwsArgumentError); |
| 237 }); | 241 }); |
| 242 |
| 243 test('Join does not modify internal ., .., or trailing separators', () { |
| 244 expect(builder.join('a/', 'b/c/'), 'a/b/c/'); |
| 245 expect(builder.join('a/b/./c/..//', 'd/.././..//e/f//'), |
| 246 'a/b/./c/..//d/.././..//e/f//'); |
| 247 expect(builder.join('a/b', 'c/../../../..'), 'a/b/c/../../../..'); |
| 248 expect(builder.join('a', 'b${builder.separator}'), 'a/b/'); |
| 249 }); |
| 238 }); | 250 }); |
| 239 | 251 |
| 240 group('joinAll', () { | 252 group('joinAll', () { |
| 241 test('allows more than eight parts', () { | 253 test('allows more than eight parts', () { |
| 242 expect(builder.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']), | 254 expect(builder.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']), |
| 243 'a/b/c/d/e/f/g/h/i'); | 255 'a/b/c/d/e/f/g/h/i'); |
| 244 }); | 256 }); |
| 245 | 257 |
| 246 test('ignores parts before an absolute path', () { | 258 test('ignores parts before an absolute path', () { |
| 247 expect(builder.joinAll(['a', 'http://dartlang.org', 'b', 'c']), | 259 expect(builder.joinAll(['a', 'http://dartlang.org', 'b', 'c']), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 expect(builder.split('http://dartlang.org'), | 310 expect(builder.split('http://dartlang.org'), |
| 299 equals(['http://dartlang.org'])); | 311 equals(['http://dartlang.org'])); |
| 300 expect(builder.split('file:///'), equals(['file://'])); | 312 expect(builder.split('file:///'), equals(['file://'])); |
| 301 expect(builder.split('file://'), equals(['file://'])); | 313 expect(builder.split('file://'), equals(['file://'])); |
| 302 expect(builder.split('/'), equals(['/'])); | 314 expect(builder.split('/'), equals(['/'])); |
| 303 }); | 315 }); |
| 304 }); | 316 }); |
| 305 | 317 |
| 306 group('normalize', () { | 318 group('normalize', () { |
| 307 test('simple cases', () { | 319 test('simple cases', () { |
| 308 expect(builder.normalize(''), ''); | 320 expect(builder.normalize(''), '.'); |
| 309 expect(builder.normalize('.'), '.'); | 321 expect(builder.normalize('.'), '.'); |
| 310 expect(builder.normalize('..'), '..'); | 322 expect(builder.normalize('..'), '..'); |
| 311 expect(builder.normalize('a'), 'a'); | 323 expect(builder.normalize('a'), 'a'); |
| 312 expect(builder.normalize('http://dartlang.org/'), 'http://dartlang.org'); | 324 expect(builder.normalize('http://dartlang.org/'), 'http://dartlang.org'); |
| 313 expect(builder.normalize('http://dartlang.org'), 'http://dartlang.org'); | 325 expect(builder.normalize('http://dartlang.org'), 'http://dartlang.org'); |
| 314 expect(builder.normalize('file://'), 'file://'); | 326 expect(builder.normalize('file://'), 'file://'); |
| 315 expect(builder.normalize('file:///'), 'file://'); | 327 expect(builder.normalize('file:///'), 'file://'); |
| 316 expect(builder.normalize('/'), '/'); | 328 expect(builder.normalize('/'), '/'); |
| 317 expect(builder.normalize(r'\'), r'\'); | 329 expect(builder.normalize(r'\'), r'\'); |
| 330 expect(builder.normalize('C:/'), 'C:'); |
| 331 expect(builder.normalize(r'C:\'), r'C:\'); |
| 332 expect(builder.normalize(r'\\'), r'\\'); |
| 333 expect(builder.normalize('a/./\xc5\u0bf8-;\u{1f085}\u{00}/c/d/../'), |
| 334 'a/\xc5\u0bf8-;\u{1f085}\u{00}/c'); |
| 318 }); | 335 }); |
| 319 | 336 |
| 320 test('collapses redundant separators', () { | 337 test('collapses redundant separators', () { |
| 321 expect(builder.normalize(r'a/b/c'), r'a/b/c'); | 338 expect(builder.normalize(r'a/b/c'), r'a/b/c'); |
| 322 expect(builder.normalize(r'a//b///c////d'), r'a/b/c/d'); | 339 expect(builder.normalize(r'a//b///c////d'), r'a/b/c/d'); |
| 323 }); | 340 }); |
| 324 | 341 |
| 325 test('does not collapse separators for other platform', () { | 342 test('does not collapse separators for other platform', () { |
| 326 expect(builder.normalize(r'a\\b\\\c'), r'a\\b\\\c'); | 343 expect(builder.normalize(r'a\\b\\\c'), r'a\\b\\\c'); |
| 327 }); | 344 }); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 353 expect(builder.normalize('file:///..'), 'file://'); | 370 expect(builder.normalize('file:///..'), 'file://'); |
| 354 expect(builder.normalize('/..'), '/'); | 371 expect(builder.normalize('/..'), '/'); |
| 355 expect(builder.normalize('http://dartlang.org/../../..'), | 372 expect(builder.normalize('http://dartlang.org/../../..'), |
| 356 'http://dartlang.org'); | 373 'http://dartlang.org'); |
| 357 expect(builder.normalize('file:///../../..'), 'file://'); | 374 expect(builder.normalize('file:///../../..'), 'file://'); |
| 358 expect(builder.normalize('/../../..'), '/'); | 375 expect(builder.normalize('/../../..'), '/'); |
| 359 expect(builder.normalize('http://dartlang.org/../../../a'), | 376 expect(builder.normalize('http://dartlang.org/../../../a'), |
| 360 'http://dartlang.org/a'); | 377 'http://dartlang.org/a'); |
| 361 expect(builder.normalize('file:///../../../a'), 'file:///a'); | 378 expect(builder.normalize('file:///../../../a'), 'file:///a'); |
| 362 expect(builder.normalize('/../../../a'), '/a'); | 379 expect(builder.normalize('/../../../a'), '/a'); |
| 380 expect(builder.normalize('c:/..'), '.'); |
| 381 expect(builder.normalize('A:/../../..'), '../..'); |
| 363 expect(builder.normalize('a/..'), '.'); | 382 expect(builder.normalize('a/..'), '.'); |
| 364 expect(builder.normalize('a/b/..'), 'a'); | 383 expect(builder.normalize('a/b/..'), 'a'); |
| 365 expect(builder.normalize('a/../b'), 'b'); | 384 expect(builder.normalize('a/../b'), 'b'); |
| 366 expect(builder.normalize('a/./../b'), 'b'); | 385 expect(builder.normalize('a/./../b'), 'b'); |
| 367 expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d'); | 386 expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d'); |
| 368 expect(builder.normalize('a/b/../../../../c'), '../../c'); | 387 expect(builder.normalize('a/b/../../../../c'), '../../c'); |
| 388 expect(builder.normalize('z/a/b/../../..\../c'), 'z/..\../c'); |
| 389 expect(builder.normalize('a/b\c/../d'), 'a/d'); |
| 369 }); | 390 }); |
| 370 | 391 |
| 371 test('does not walk before root on absolute paths', () { | 392 test('does not walk before root on absolute paths', () { |
| 372 expect(builder.normalize('..'), '..'); | 393 expect(builder.normalize('..'), '..'); |
| 373 expect(builder.normalize('../'), '..'); | 394 expect(builder.normalize('../'), '..'); |
| 374 expect(builder.normalize('http://dartlang.org/..'), | 395 expect(builder.normalize('http://dartlang.org/..'), |
| 375 'http://dartlang.org'); | 396 'http://dartlang.org'); |
| 397 expect(builder.normalize('http://dartlang.org/../a'), |
| 398 'http://dartlang.org/a'); |
| 376 expect(builder.normalize('file:///..'), 'file://'); | 399 expect(builder.normalize('file:///..'), 'file://'); |
| 400 expect(builder.normalize('file:///../a'), 'file:///a'); |
| 377 expect(builder.normalize('/..'), '/'); | 401 expect(builder.normalize('/..'), '/'); |
| 378 expect(builder.normalize('a/..'), '.'); | 402 expect(builder.normalize('a/..'), '.'); |
| 403 expect(builder.normalize('../a'), '../a'); |
| 404 expect(builder.normalize('/../a'), '/a'); |
| 405 expect(builder.normalize('c:/../a'), 'a'); |
| 406 expect(builder.normalize('/../a'), '/a'); |
| 379 expect(builder.normalize('a/b/..'), 'a'); | 407 expect(builder.normalize('a/b/..'), 'a'); |
| 408 expect(builder.normalize('../a/b/..'), '../a'); |
| 380 expect(builder.normalize('a/../b'), 'b'); | 409 expect(builder.normalize('a/../b'), 'b'); |
| 381 expect(builder.normalize('a/./../b'), 'b'); | 410 expect(builder.normalize('a/./../b'), 'b'); |
| 382 expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d'); | 411 expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d'); |
| 383 expect(builder.normalize('a/b/../../../../c'), '../../c'); | 412 expect(builder.normalize('a/b/../../../../c'), '../../c'); |
| 413 expect(builder.normalize('a/b/c/../../..d/./.e/f././'), 'a/..d/.e/f.'); |
| 384 }); | 414 }); |
| 385 | 415 |
| 386 test('removes trailing separators', () { | 416 test('removes trailing separators', () { |
| 387 expect(builder.normalize('./'), '.'); | 417 expect(builder.normalize('./'), '.'); |
| 388 expect(builder.normalize('.//'), '.'); | 418 expect(builder.normalize('.//'), '.'); |
| 389 expect(builder.normalize('a/'), 'a'); | 419 expect(builder.normalize('a/'), 'a'); |
| 390 expect(builder.normalize('a/b/'), 'a/b'); | 420 expect(builder.normalize('a/b/'), 'a/b'); |
| 421 expect(builder.normalize(r'a/b\'), r'a/b\'); |
| 391 expect(builder.normalize('a/b///'), 'a/b'); | 422 expect(builder.normalize('a/b///'), 'a/b'); |
| 392 }); | 423 }); |
| 393 }); | 424 }); |
| 394 | 425 |
| 395 group('relative', () { | 426 group('relative', () { |
| 396 group('from absolute root', () { | 427 group('from absolute root', () { |
| 397 test('given absolute path in root', () { | 428 test('given absolute path in root', () { |
| 398 expect(builder.relative('http://dartlang.org'), '../..'); | 429 expect(builder.relative('http://dartlang.org'), '../..'); |
| 399 expect(builder.relative('http://dartlang.org/'), '../..'); | 430 expect(builder.relative('http://dartlang.org/'), '../..'); |
| 400 expect(builder.relative('/'), '../..'); | 431 expect(builder.relative('/'), '../..'); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 Uri.parse('http://dartlang.org/path/to/foo')); | 683 Uri.parse('http://dartlang.org/path/to/foo')); |
| 653 expect(builder.toUri('http://dartlang.org/path/to/foo/'), | 684 expect(builder.toUri('http://dartlang.org/path/to/foo/'), |
| 654 Uri.parse('http://dartlang.org/path/to/foo/')); | 685 Uri.parse('http://dartlang.org/path/to/foo/')); |
| 655 expect(builder.toUri('file:///path/to/foo'), | 686 expect(builder.toUri('file:///path/to/foo'), |
| 656 Uri.parse('file:///path/to/foo')); | 687 Uri.parse('file:///path/to/foo')); |
| 657 expect(builder.toUri('foo/bar'), Uri.parse('foo/bar')); | 688 expect(builder.toUri('foo/bar'), Uri.parse('foo/bar')); |
| 658 expect(builder.toUri('http://dartlang.org/path/to/foo%23bar'), | 689 expect(builder.toUri('http://dartlang.org/path/to/foo%23bar'), |
| 659 Uri.parse('http://dartlang.org/path/to/foo%23bar')); | 690 Uri.parse('http://dartlang.org/path/to/foo%23bar')); |
| 660 }); | 691 }); |
| 661 } | 692 } |
| OLD | NEW |