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

Side by Side Diff: pkg/path/test/posix_test.dart

Issue 59483008: Add isWithin to pkg/path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « pkg/path/lib/path.dart ('k') | pkg/path/test/relative_test.dart » ('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.posix_test; 5 library path.test.posix_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 import 'utils.dart';
11
10 main() { 12 main() {
11 var builder = new path.Builder(style: path.Style.posix, root: '/root/path'); 13 var builder = new path.Builder(style: path.Style.posix, root: '/root/path');
12 14
13 if (new path.Builder().style == path.Style.posix) { 15 if (new path.Builder().style == path.Style.posix) {
14 group('absolute', () { 16 group('absolute', () {
15 expect(path.absolute('a/b.txt'), path.join(path.current, 'a/b.txt')); 17 expect(path.absolute('a/b.txt'), path.join(path.current, 'a/b.txt'));
16 expect(path.absolute('/a/b.txt'), '/a/b.txt'); 18 expect(path.absolute('/a/b.txt'), '/a/b.txt');
17 }); 19 });
18 } 20 }
19 21
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 expect(builder.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz')); 393 expect(builder.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz'));
392 expect(builder.relative('..', from: '/foo/bar'), equals('../../root')); 394 expect(builder.relative('..', from: '/foo/bar'), equals('../../root'));
393 expect(builder.relative('/foo/bar/baz', from: 'foo/bar'), 395 expect(builder.relative('/foo/bar/baz', from: 'foo/bar'),
394 equals('../../../../foo/bar/baz')); 396 equals('../../../../foo/bar/baz'));
395 expect(builder.relative('..', from: 'foo/bar'), equals('../../..')); 397 expect(builder.relative('..', from: 'foo/bar'), equals('../../..'));
396 }); 398 });
397 399
398 test('with a root parameter and a relative root', () { 400 test('with a root parameter and a relative root', () {
399 var r = new path.Builder(style: path.Style.posix, root: 'relative/root'); 401 var r = new path.Builder(style: path.Style.posix, root: 'relative/root');
400 expect(r.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz')); 402 expect(r.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz'));
401 expect(() => r.relative('..', from: '/foo/bar'), throwsArgumentError); 403 expect(() => r.relative('..', from: '/foo/bar'), throwsPathException);
402 expect(r.relative('/foo/bar/baz', from: 'foo/bar'), 404 expect(r.relative('/foo/bar/baz', from: 'foo/bar'),
403 equals('/foo/bar/baz')); 405 equals('/foo/bar/baz'));
404 expect(r.relative('..', from: 'foo/bar'), equals('../../..')); 406 expect(r.relative('..', from: 'foo/bar'), equals('../../..'));
405 }); 407 });
406 408
407 test('from a . root', () { 409 test('from a . root', () {
408 var r = new path.Builder(style: path.Style.posix, root: '.'); 410 var r = new path.Builder(style: path.Style.posix, root: '.');
409 expect(r.relative('/foo/bar/baz'), equals('/foo/bar/baz')); 411 expect(r.relative('/foo/bar/baz'), equals('/foo/bar/baz'));
410 expect(r.relative('foo/bar/baz'), equals('foo/bar/baz')); 412 expect(r.relative('foo/bar/baz'), equals('foo/bar/baz'));
411 }); 413 });
412 }); 414 });
413 415
416 group('isWithin', () {
417 test('simple cases', () {
418 expect(builder.isWithin('foo/bar', 'foo/bar'), isFalse);
419 expect(builder.isWithin('foo/bar', 'foo/bar/baz'), isTrue);
420 expect(builder.isWithin('foo/bar', 'foo/baz'), isFalse);
421 expect(builder.isWithin('foo/bar', '../path/foo/bar/baz'), isTrue);
422 expect(builder.isWithin('/', '/foo/bar'), isTrue);
423 expect(builder.isWithin('baz', '/root/path/baz/bang'), isTrue);
424 expect(builder.isWithin('baz', '/root/path/bang/baz'), isFalse);
425 });
426
427 test('from a relative root', () {
428 var r = new path.Builder(style: path.Style.posix, root: 'foo/bar');
429 expect(builder.isWithin('.', 'a/b/c'), isTrue);
430 expect(builder.isWithin('.', '../a/b/c'), isFalse);
431 expect(builder.isWithin('.', '../../a/foo/b/c'), isFalse);
432 expect(builder.isWithin('/', '/baz/bang'), isTrue);
433 expect(builder.isWithin('.', '/baz/bang'), isFalse);
434 });
435 });
436
414 group('resolve', () { 437 group('resolve', () {
415 test('allows up to seven parts', () { 438 test('allows up to seven parts', () {
416 expect(builder.resolve('a'), '/root/path/a'); 439 expect(builder.resolve('a'), '/root/path/a');
417 expect(builder.resolve('a', 'b'), '/root/path/a/b'); 440 expect(builder.resolve('a', 'b'), '/root/path/a/b');
418 expect(builder.resolve('a', 'b', 'c'), '/root/path/a/b/c'); 441 expect(builder.resolve('a', 'b', 'c'), '/root/path/a/b/c');
419 expect(builder.resolve('a', 'b', 'c', 'd'), '/root/path/a/b/c/d'); 442 expect(builder.resolve('a', 'b', 'c', 'd'), '/root/path/a/b/c/d');
420 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), '/root/path/a/b/c/d/e'); 443 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), '/root/path/a/b/c/d/e');
421 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f'), 444 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f'),
422 '/root/path/a/b/c/d/e/f'); 445 '/root/path/a/b/c/d/e/f');
423 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f', 'g'), 446 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f', 'g'),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 expect(builder.toUri('/'), Uri.parse('file:///')); 499 expect(builder.toUri('/'), Uri.parse('file:///'));
477 expect(builder.toUri('foo/bar'), Uri.parse('foo/bar')); 500 expect(builder.toUri('foo/bar'), Uri.parse('foo/bar'));
478 expect(builder.toUri('/path/to/foo#bar'), 501 expect(builder.toUri('/path/to/foo#bar'),
479 Uri.parse('file:///path/to/foo%23bar')); 502 Uri.parse('file:///path/to/foo%23bar'));
480 expect(builder.toUri(r'/_{_}_`_^_ _"_%_'), 503 expect(builder.toUri(r'/_{_}_`_^_ _"_%_'),
481 Uri.parse('file:///_%7B_%7D_%60_%5E_%20_%22_%25_')); 504 Uri.parse('file:///_%7B_%7D_%60_%5E_%20_%22_%25_'));
482 expect(builder.toUri(r'_{_}_`_^_ _"_%_'), 505 expect(builder.toUri(r'_{_}_`_^_ _"_%_'),
483 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); 506 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_'));
484 }); 507 });
485 } 508 }
OLDNEW
« no previous file with comments | « pkg/path/lib/path.dart ('k') | pkg/path/test/relative_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698