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.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 main() { | 10 main() { |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 expect(r.relative('..', from: 'foo/bar'), equals('../../..')); | 404 expect(r.relative('..', from: 'foo/bar'), equals('../../..')); |
405 }); | 405 }); |
406 | 406 |
407 test('from a . root', () { | 407 test('from a . root', () { |
408 var r = new path.Builder(style: path.Style.posix, root: '.'); | 408 var r = new path.Builder(style: path.Style.posix, root: '.'); |
409 expect(r.relative('/foo/bar/baz'), equals('/foo/bar/baz')); | 409 expect(r.relative('/foo/bar/baz'), equals('/foo/bar/baz')); |
410 expect(r.relative('foo/bar/baz'), equals('foo/bar/baz')); | 410 expect(r.relative('foo/bar/baz'), equals('foo/bar/baz')); |
411 }); | 411 }); |
412 }); | 412 }); |
413 | 413 |
| 414 group('isWithin', () { |
| 415 test('simple cases', () { |
| 416 expect(builder.isWithin('foo/bar', 'foo/bar'), isFalse); |
| 417 expect(builder.isWithin('foo/bar', 'foo/bar/baz'), isTrue); |
| 418 expect(builder.isWithin('foo/bar', 'foo/baz'), isFalse); |
| 419 expect(builder.isWithin('foo/bar', '../path/foo/bar/baz'), isTrue); |
| 420 expect(builder.isWithin('/', '/foo/bar'), isTrue); |
| 421 expect(builder.isWithin('baz', '/root/path/baz/bang'), isTrue); |
| 422 expect(builder.isWithin('baz', '/root/path/bang/baz'), isFalse); |
| 423 }); |
| 424 |
| 425 test('from a relative root', () { |
| 426 var r = new path.Builder(style: path.Style.posix, root: 'foo/bar'); |
| 427 expect(builder.isWithin('.', 'a/b/c'), isTrue); |
| 428 expect(builder.isWithin('.', '../a/b/c'), isFalse); |
| 429 expect(builder.isWithin('.', '../../a/foo/b/c'), isFalse); |
| 430 expect(builder.isWithin('/', '/baz/bang'), isTrue); |
| 431 expect(builder.isWithin('.', '/baz/bang'), isFalse); |
| 432 }); |
| 433 }); |
| 434 |
414 group('resolve', () { | 435 group('resolve', () { |
415 test('allows up to seven parts', () { | 436 test('allows up to seven parts', () { |
416 expect(builder.resolve('a'), '/root/path/a'); | 437 expect(builder.resolve('a'), '/root/path/a'); |
417 expect(builder.resolve('a', 'b'), '/root/path/a/b'); | 438 expect(builder.resolve('a', 'b'), '/root/path/a/b'); |
418 expect(builder.resolve('a', 'b', 'c'), '/root/path/a/b/c'); | 439 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'); | 440 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'); | 441 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'), | 442 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f'), |
422 '/root/path/a/b/c/d/e/f'); | 443 '/root/path/a/b/c/d/e/f'); |
423 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f', 'g'), | 444 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f', 'g'), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 expect(builder.toUri('/'), Uri.parse('file:///')); | 497 expect(builder.toUri('/'), Uri.parse('file:///')); |
477 expect(builder.toUri('foo/bar'), Uri.parse('foo/bar')); | 498 expect(builder.toUri('foo/bar'), Uri.parse('foo/bar')); |
478 expect(builder.toUri('/path/to/foo#bar'), | 499 expect(builder.toUri('/path/to/foo#bar'), |
479 Uri.parse('file:///path/to/foo%23bar')); | 500 Uri.parse('file:///path/to/foo%23bar')); |
480 expect(builder.toUri(r'/_{_}_`_^_ _"_%_'), | 501 expect(builder.toUri(r'/_{_}_`_^_ _"_%_'), |
481 Uri.parse('file:///_%7B_%7D_%60_%5E_%20_%22_%25_')); | 502 Uri.parse('file:///_%7B_%7D_%60_%5E_%20_%22_%25_')); |
482 expect(builder.toUri(r'_{_}_`_^_ _"_%_'), | 503 expect(builder.toUri(r'_{_}_`_^_ _"_%_'), |
483 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); | 504 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); |
484 }); | 505 }); |
485 } | 506 } |
OLD | NEW |