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

Side by Side Diff: packages/path/test/windows_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 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
« no previous file with comments | « packages/path/test/utils.dart ('k') | packages/petitparser/.gitignore » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library path.test.windows_test;
6
7 import 'package:test/test.dart'; 5 import 'package:test/test.dart';
8 import 'package:path/path.dart' as path; 6 import 'package:path/path.dart' as path;
9 7
10 import 'utils.dart'; 8 import 'utils.dart';
11 9
12 main() { 10 main() {
13 var context = 11 var context =
14 new path.Context(style: path.Style.windows, current: r'C:\root\path'); 12 new path.Context(style: path.Style.windows, current: r'C:\root\path');
15 13
16 test('separator', () { 14 test('separator', () {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 }); 323 });
326 324
327 test('collapses redundant separators', () { 325 test('collapses redundant separators', () {
328 expect(context.normalize(r'a\b\c'), r'a\b\c'); 326 expect(context.normalize(r'a\b\c'), r'a\b\c');
329 expect(context.normalize(r'a\\b\\\c\\\\d'), r'a\b\c\d'); 327 expect(context.normalize(r'a\\b\\\c\\\\d'), r'a\b\c\d');
330 }); 328 });
331 329
332 test('eliminates "." parts', () { 330 test('eliminates "." parts', () {
333 expect(context.normalize(r'.\'), '.'); 331 expect(context.normalize(r'.\'), '.');
334 expect(context.normalize(r'c:\.'), r'c:\'); 332 expect(context.normalize(r'c:\.'), r'c:\');
333 expect(context.normalize(r'c:\foo\.'), r'c:\foo');
335 expect(context.normalize(r'B:\.\'), r'B:\'); 334 expect(context.normalize(r'B:\.\'), r'B:\');
336 expect(context.normalize(r'\\server\share\.'), r'\\server\share'); 335 expect(context.normalize(r'\\server\share\.'), r'\\server\share');
337 expect(context.normalize(r'.\.'), '.'); 336 expect(context.normalize(r'.\.'), '.');
338 expect(context.normalize(r'a\.\b'), r'a\b'); 337 expect(context.normalize(r'a\.\b'), r'a\b');
339 expect(context.normalize(r'a\.b\c'), r'a\.b\c'); 338 expect(context.normalize(r'a\.b\c'), r'a\.b\c');
340 expect(context.normalize(r'a\./.\b\.\c'), r'a\b\c'); 339 expect(context.normalize(r'a\./.\b\.\c'), r'a\b\c');
341 expect(context.normalize(r'.\./a'), 'a'); 340 expect(context.normalize(r'.\./a'), 'a');
342 expect(context.normalize(r'a/.\.'), 'a'); 341 expect(context.normalize(r'a/.\.'), 'a');
343 expect(context.normalize(r'\.'), r'\'); 342 expect(context.normalize(r'\.'), r'\');
344 expect(context.normalize('/.'), r'\'); 343 expect(context.normalize('/.'), r'\');
345 }); 344 });
346 345
347 test('eliminates ".." parts', () { 346 test('eliminates ".." parts', () {
348 expect(context.normalize('..'), '..'); 347 expect(context.normalize('..'), '..');
349 expect(context.normalize(r'..\'), '..'); 348 expect(context.normalize(r'..\'), '..');
350 expect(context.normalize(r'..\..\..'), r'..\..\..'); 349 expect(context.normalize(r'..\..\..'), r'..\..\..');
351 expect(context.normalize(r'../..\..\'), r'..\..\..'); 350 expect(context.normalize(r'../..\..\'), r'..\..\..');
352 expect(context.normalize(r'\\server\share\..'), r'\\server\share'); 351 expect(context.normalize(r'\\server\share\..'), r'\\server\share');
353 expect( 352 expect(
354 context.normalize(r'\\server\share\..\../..\a'), r'\\server\share\a'); 353 context.normalize(r'\\server\share\..\../..\a'), r'\\server\share\a');
355 expect(context.normalize(r'c:\..'), r'c:\'); 354 expect(context.normalize(r'c:\..'), r'c:\');
355 expect(context.normalize(r'c:\foo\..'), r'c:\');
356 expect(context.normalize(r'A:/..\..\..'), r'A:\'); 356 expect(context.normalize(r'A:/..\..\..'), r'A:\');
357 expect(context.normalize(r'b:\..\..\..\a'), r'b:\a'); 357 expect(context.normalize(r'b:\..\..\..\a'), r'b:\a');
358 expect(context.normalize(r'b:\r\..\..\..\a\c\.\..'), r'b:\a'); 358 expect(context.normalize(r'b:\r\..\..\..\a\c\.\..'), r'b:\a');
359 expect(context.normalize(r'a\..'), '.'); 359 expect(context.normalize(r'a\..'), '.');
360 expect(context.normalize(r'..\a'), r'..\a'); 360 expect(context.normalize(r'..\a'), r'..\a');
361 expect(context.normalize(r'c:\..\a'), r'c:\a'); 361 expect(context.normalize(r'c:\..\a'), r'c:\a');
362 expect(context.normalize(r'\..\a'), r'\a'); 362 expect(context.normalize(r'\..\a'), r'\a');
363 expect(context.normalize(r'a\b\..'), 'a'); 363 expect(context.normalize(r'a\b\..'), 'a');
364 expect(context.normalize(r'..\a\b\..'), r'..\a'); 364 expect(context.normalize(r'..\a\b\..'), r'..\a');
365 expect(context.normalize(r'a\..\b'), 'b'); 365 expect(context.normalize(r'a\..\b'), 'b');
366 expect(context.normalize(r'a\.\..\b'), 'b'); 366 expect(context.normalize(r'a\.\..\b'), 'b');
367 expect(context.normalize(r'a\b\c\..\..\d\e\..'), r'a\d'); 367 expect(context.normalize(r'a\b\c\..\..\d\e\..'), r'a\d');
368 expect(context.normalize(r'a\b\..\..\..\..\c'), r'..\..\c'); 368 expect(context.normalize(r'a\b\..\..\..\..\c'), r'..\..\c');
369 expect(context.normalize(r'a/b/c/../../..d/./.e/f././'), r'a\..d\.e\f.'); 369 expect(context.normalize(r'a/b/c/../../..d/./.e/f././'), r'a\..d\.e\f.');
370 }); 370 });
371 371
372 test('removes trailing separators', () { 372 test('removes trailing separators', () {
373 expect(context.normalize(r'.\'), '.'); 373 expect(context.normalize(r'.\'), '.');
374 expect(context.normalize(r'.\\'), '.'); 374 expect(context.normalize(r'.\\'), '.');
375 expect(context.normalize(r'a/'), 'a'); 375 expect(context.normalize(r'a/'), 'a');
376 expect(context.normalize(r'a\b\'), r'a\b'); 376 expect(context.normalize(r'a\b\'), r'a\b');
377 expect(context.normalize(r'a\b\\\'), r'a\b'); 377 expect(context.normalize(r'a\b\\\'), r'a\b');
378 }); 378 });
379 379
380 test('normalizes separators', () { 380 test('normalizes separators', () {
381 expect(context.normalize(r'a/b\c'), r'a\b\c'); 381 expect(context.normalize(r'a/b\c'), r'a\b\c');
382 }); 382 });
383
384 test('when canonicalizing', () {
385 expect(context.canonicalize('.'), r'c:\root\path');
386 expect(context.canonicalize('foo/bar'), r'c:\root\path\foo\bar');
387 expect(context.canonicalize('FoO'), r'c:\root\path\foo');
388 expect(context.canonicalize('/foo'), r'c:\foo');
389 expect(context.canonicalize('D:/foo'), r'd:\foo');
390 });
383 }); 391 });
384 392
385 group('relative', () { 393 group('relative', () {
386 group('from absolute root', () { 394 group('from absolute root', () {
387 test('given absolute path in root', () { 395 test('given absolute path in root', () {
388 expect(context.relative(r'C:\'), r'..\..'); 396 expect(context.relative(r'C:\'), r'..\..');
389 expect(context.relative(r'C:\root'), '..'); 397 expect(context.relative(r'C:\root'), '..');
390 expect(context.relative(r'\root'), '..'); 398 expect(context.relative(r'\root'), '..');
391 expect(context.relative(r'C:\root\path'), '.'); 399 expect(context.relative(r'C:\root\path'), '.');
392 expect(context.relative(r'\root\path'), '.'); 400 expect(context.relative(r'\root\path'), '.');
(...skipping 27 matching lines...) Expand all
420 // The path is considered relative to the root, so it basically just 428 // The path is considered relative to the root, so it basically just
421 // normalizes. 429 // normalizes.
422 expect(context.relative(''), '.'); 430 expect(context.relative(''), '.');
423 expect(context.relative('.'), '.'); 431 expect(context.relative('.'), '.');
424 expect(context.relative('a'), 'a'); 432 expect(context.relative('a'), 'a');
425 expect(context.relative(r'a\b.txt'), r'a\b.txt'); 433 expect(context.relative(r'a\b.txt'), r'a\b.txt');
426 expect(context.relative(r'..\a\b.txt'), r'..\a\b.txt'); 434 expect(context.relative(r'..\a\b.txt'), r'..\a\b.txt');
427 expect(context.relative(r'a\.\b\..\c.txt'), r'a\c.txt'); 435 expect(context.relative(r'a\.\b\..\c.txt'), r'a\c.txt');
428 }); 436 });
429 437
438 test('is case-insensitive', () {
439 expect(context.relative(r'c:\'), r'..\..');
440 expect(context.relative(r'c:\RoOt'), r'..');
441 expect(context.relative(r'c:\rOoT\pAtH\a'), r'a');
442 });
443
430 // Regression 444 // Regression
431 test('from root-only path', () { 445 test('from root-only path', () {
432 expect(context.relative(r'C:\', from: r'C:\'), '.'); 446 expect(context.relative(r'C:\', from: r'C:\'), '.');
433 expect(context.relative(r'C:\root\path', from: r'C:\'), r'root\path'); 447 expect(context.relative(r'C:\root\path', from: r'C:\'), r'root\path');
434 }); 448 });
435 }); 449 });
436 450
437 group('from relative root', () { 451 group('from relative root', () {
438 var r = new path.Context(style: path.Style.windows, current: r'foo\bar'); 452 var r = new path.Context(style: path.Style.windows, current: r'foo\bar');
439 453
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 }); 576 });
563 577
564 test('from a relative root', () { 578 test('from a relative root', () {
565 var r = new path.Context(style: path.Style.windows, current: r'foo\bar'); 579 var r = new path.Context(style: path.Style.windows, current: r'foo\bar');
566 expect(r.isWithin('.', r'a\b\c'), isTrue); 580 expect(r.isWithin('.', r'a\b\c'), isTrue);
567 expect(r.isWithin('.', r'..\a\b\c'), isFalse); 581 expect(r.isWithin('.', r'..\a\b\c'), isFalse);
568 expect(r.isWithin('.', r'..\..\a\foo\b\c'), isFalse); 582 expect(r.isWithin('.', r'..\..\a\foo\b\c'), isFalse);
569 expect(r.isWithin(r'C:\', r'C:\baz\bang'), isTrue); 583 expect(r.isWithin(r'C:\', r'C:\baz\bang'), isTrue);
570 expect(r.isWithin('.', r'C:\baz\bang'), isFalse); 584 expect(r.isWithin('.', r'C:\baz\bang'), isFalse);
571 }); 585 });
586
587 test('is case-insensitive', () {
588 expect(context.isWithin(r'FoO', r'fOo\bar'), isTrue);
589 expect(context.isWithin(r'C:\', r'c:\foo'), isTrue);
590 expect(context.isWithin(r'fOo\qux\..\BaR', r'FoO\bAr\baz'), isTrue);
591 });
592 });
593
594 group('equals and hash', () {
595 test('simple cases', () {
596 expectEquals(context, r'foo\bar', r'foo\bar');
597 expectNotEquals(context, r'foo\bar', r'foo\bar\baz');
598 expectNotEquals(context, r'foo\bar', r'foo');
599 expectNotEquals(context, r'foo\bar', r'foo\baz');
600 expectEquals(context, r'foo\bar', r'..\path\foo\bar');
601 expectEquals(context, r'D:\', r'D:\');
602 expectEquals(context, r'C:\', r'..\..');
603 expectEquals(context, r'baz', r'C:\root\path\baz');
604 });
605
606 test('complex cases', () {
607 expectEquals(context, r'foo\.\bar', r'foo\bar');
608 expectEquals(context, r'foo\\bar', r'foo\bar');
609 expectEquals(context, r'foo\qux\..\bar', r'foo\bar');
610 expectNotEquals(context, r'foo\qux\..\bar', r'foo\qux');
611 expectNotEquals(context, r'foo\bar', r'foo\bar\baz\..\..');
612 expectEquals(context, r'foo\bar', r'foo\bar\\\');
613 expectEquals(context, r'foo\.bar', r'foo\.bar');
614 expectNotEquals(context, r'foo\.\bar', r'foo\.bar');
615 expectEquals(context, r'foo\..bar', r'foo\..bar');
616 expectNotEquals(context, r'foo\..\bar', r'foo\..bar');
617 expectEquals(context, r'foo\bar', r'foo\bar\baz\..');
618 expectEquals(context, r'FoO\bAr', r'foo\bar');
619 expectEquals(context, r'foo/\bar', r'foo\/bar');
620 expectEquals(context, r'c:\', r'C:\');
621 expectEquals(context, r'C:\root', r'..');
622 });
623
624 test('with root-relative paths', () {
625 expectEquals(context, r'\foo', r'C:\foo');
626 expectNotEquals(context, r'\foo', 'http://google.com/foo');
627 expectEquals(context, r'C:\root\path\foo\bar', r'foo\bar');
628 });
629
630 test('from a relative root', () {
631 var r = new path.Context(style: path.Style.windows, current: r'foo\bar');
632 expectEquals(r, r'a\b', r'a\b');
633 expectNotEquals(r, '.', r'foo\bar');
634 expectNotEquals(r, '.', r'..\a\b');
635 expectEquals(r, '.', r'..\bar');
636 expectEquals(r, r'C:\baz\bang', r'C:\baz\bang');
637 expectNotEquals(r, r'baz\bang', r'C:\baz\bang');
638 });
572 }); 639 });
573 640
574 group('absolute', () { 641 group('absolute', () {
575 test('allows up to seven parts', () { 642 test('allows up to seven parts', () {
576 expect(context.absolute('a'), r'C:\root\path\a'); 643 expect(context.absolute('a'), r'C:\root\path\a');
577 expect(context.absolute('a', 'b'), r'C:\root\path\a\b'); 644 expect(context.absolute('a', 'b'), r'C:\root\path\a\b');
578 expect(context.absolute('a', 'b', 'c'), r'C:\root\path\a\b\c'); 645 expect(context.absolute('a', 'b', 'c'), r'C:\root\path\a\b\c');
579 expect(context.absolute('a', 'b', 'c', 'd'), r'C:\root\path\a\b\c\d'); 646 expect(context.absolute('a', 'b', 'c', 'd'), r'C:\root\path\a\b\c\d');
580 expect( 647 expect(
581 context.absolute('a', 'b', 'c', 'd', 'e'), r'C:\root\path\a\b\c\d\e'); 648 context.absolute('a', 'b', 'c', 'd', 'e'), r'C:\root\path\a\b\c\d\e');
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 context.fromUri(Uri.parse('///C:/path/to/foo')), r'C:\path\to\foo'); 699 context.fromUri(Uri.parse('///C:/path/to/foo')), r'C:\path\to\foo');
633 expect(context.fromUri(Uri.parse('//server/share/path/to/foo')), 700 expect(context.fromUri(Uri.parse('//server/share/path/to/foo')),
634 r'\\server\share\path\to\foo'); 701 r'\\server\share\path\to\foo');
635 expect(context.fromUri(Uri.parse('file:///C:/path/to/foo%23bar')), 702 expect(context.fromUri(Uri.parse('file:///C:/path/to/foo%23bar')),
636 r'C:\path\to\foo#bar'); 703 r'C:\path\to\foo#bar');
637 expect( 704 expect(
638 context.fromUri(Uri.parse('file://server/share/path/to/foo%23bar')), 705 context.fromUri(Uri.parse('file://server/share/path/to/foo%23bar')),
639 r'\\server\share\path\to\foo#bar'); 706 r'\\server\share\path\to\foo#bar');
640 expect(context.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')), 707 expect(context.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')),
641 r'_{_}_`_^_ _"_%_'); 708 r'_{_}_`_^_ _"_%_');
709 expect(context.fromUri(Uri.parse('/foo')), r'\foo');
642 expect(() => context.fromUri(Uri.parse('http://dartlang.org')), 710 expect(() => context.fromUri(Uri.parse('http://dartlang.org')),
643 throwsArgumentError); 711 throwsArgumentError);
644 }); 712 });
645 713
646 test('with a string', () { 714 test('with a string', () {
647 expect(context.fromUri('file:///C:/path/to/foo'), r'C:\path\to\foo'); 715 expect(context.fromUri('file:///C:/path/to/foo'), r'C:\path\to\foo');
648 }); 716 });
649 }); 717 });
650 718
651 test('toUri', () { 719 test('toUri', () {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 759
692 test('with a root-relative URI', () { 760 test('with a root-relative URI', () {
693 expect(context.prettyUri('/D:/a/b'), r'D:\a\b'); 761 expect(context.prettyUri('/D:/a/b'), r'D:\a\b');
694 }); 762 });
695 763
696 test('with a Uri object', () { 764 test('with a Uri object', () {
697 expect(context.prettyUri(Uri.parse('a/b')), r'a\b'); 765 expect(context.prettyUri(Uri.parse('a/b')), r'a\b');
698 }); 766 });
699 }); 767 });
700 } 768 }
OLDNEW
« no previous file with comments | « packages/path/test/utils.dart ('k') | packages/petitparser/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698