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

Side by Side Diff: tests/standalone/io/path_test.dart

Issue 10417053: Add Path class to dart:io, and add unit tests for it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 6 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 | Annotate | Revision Log
« runtime/bin/path_impl.dart ('K') | « runtime/bin/path_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // Test the Path class in dart:io.
6
7 #import("dart:io");
8
9 void main() {
10 testBaseFunctions();
11 testCanonicalize();
12 }
13
14 void testBaseFunctions() {
15 testGetters(new Path("/foo/bar/fisk.hest"),
16 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'],
17 'absolute canonical');
18 testGetters(new Path("/foo/bar/fisk.hest"),
19 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'],
20 'absolute canonical');
21 testGetters(new Path("/foo/bar/fisk.hest"),
22 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'],
23 'absolute canonical');
24 testGetters(new Path(''),
25 ['', '', '', ''],
26 'empty');
27 // This corner case leaves a trailing slash for the root.
28 testGetters(new Path('/'),
29 ['/', '', '', ''],
30 'absolute directory canonical trailing');
31 testGetters(new Path('.'),
32 ['', '.', '', ''],
33 'canonical');
34 testGetters(new Path('/ab,;- .c.d'),
35 ['/', 'ab,;- .c.d', 'ab,;- .c', 'd'],
36 'absolute directory canonical');
37
38 // Canonical and non-canonical cases
39 testGetters(new Path("a/b/../c/./d/e"),
40 ['a/b/../c/./d', 'e', 'e', ''],
41 '');
42 testGetters(new Path("a./b../..c/.d/e"),
43 ['a./b../..c/.d', 'e', 'e', ''],
44 'canonical');
45 // .. is allowed at the beginning of a canonical relative path.
46 testGetters(new Path("../../a/b/c/d/"),
47 ['../../a/b/c/d', '', '', ''],
48 'canonical directory trailing');
49
50 // Test the special path cleaning operations on the Windows platform.
51 if (Platform.operatingSystem == 'windows') {
52 testGetters(new Path.fromNative(@"c:\foo\bar\fisk.hest"),
53 ['/c:/foo/bar', 'fisk.hest', 'fisk', 'hest'],
54 'absolute canonical');
55 testGetters(new Path.fromNative("\\foo\\bar\\"),
56 ['/foo/bar', '', '', ''],
57 'absolute directory canonical trailing');
58 testGetters(new Path.fromNative("\\foo\\bar\\hest"),
59 ['/foo/bar', 'hest', 'hest', ''],
60 'absolute canonical');
61 testGetters(new Path.fromNative(@"foo/bar\hest/.fisk"),
62 ['foo/bar/hest', '.fisk', '', 'fisk'],
63 'canonical');
64 testGetters(new Path.fromNative(@"foo//bar\\hest/\/.fisk"),
65 ['foo//bar//hest//', '.fisk', '', 'fisk'],
66 '');
67 } else {
68 // Make sure that backslashes are uninterpreted on other platforms.
69 testGetters(new Path.fromNative(@"/foo\bar/bif/fisk.hest"),
70 [@'/foo\bar/bif', 'fisk.hest', 'fisk', 'hest'],
71 'absolute canonical');
72 testGetters(new Path.fromNative(@"//foo\bar///bif////fisk.hest"),
73 [@'//foo\bar///bif', 'fisk.hest', 'fisk', 'hest'],
74 'absolute');
75 testGetters(new Path.fromNative(@"/foo\ bar/bif/gule\ fisk.hest"),
76 [@'/foo\ bar/bif', @'gule\ fisk.hest', @'gule\ fisk', 'hest'],
77 'absolute canonical');
78 }
79 }
80
81
82 void testGetters(Path path, List components, String properties) {
83 final int DIRNAME = 0;
84 final int FILENAME = 1;
85 final int BASENAME = 2;
86 final int EXTENSION = 3;
87 Expect.equals(components[DIRNAME], path.directoryPath.toString());
88 Expect.equals(components[FILENAME], path.filename);
89 Expect.equals(components[BASENAME], path.filenameWithoutExtension);
90 Expect.equals(components[EXTENSION], path.extension);
91
92 Expect.equals(path.isCanonical, properties.contains('canonical'));
93 Expect.equals(path.isAbsolute, properties.contains('absolute'));
94 Expect.equals(path.hasTrailingSeparator, properties.contains('trailing'));
95 }
96
97 void testCanonicalize() {
98 Function t = (input, canonicalized) {
99 Expect.equals(canonicalized, new Path(input).canonicalize().toString());
100 };
101
102 t('.', '.');
103 t('./.', '.');
104 t('foo/..', '.');
105 t('../foo', '../foo');
106 t('/../foo', '/foo');
107 t('/foo/..', '/');
108 t('/foo/../', '/');
109 t('/c:/../foo', '/c:/foo');
110 t('/c:/foo/..', '/c:/');
111 t('/c:/foo/../', '/c:/');
112 t('/c:/foo/../..', '/c:/');
113 t('/c:/foo/../../', '/c:/');
114 t('..', '..');
115 t('', '.');
116 t('/', '/');
117 t('../foo/bar/..', '../foo');
118 t('/../foo/bar/..', '/foo');
119 t('foo/bar/../../../joe/../..', '../..');
120 t('a/b/c/../../..d/./.e/f././', 'a/..d/.e/f./');
121 t('/%:/foo/../..', '/%:/');
122 t('c:/foo/../../..', '..');
123 t('c:/foo/../../bad/dad/./..', 'bad');
124 }
OLDNEW
« runtime/bin/path_impl.dart ('K') | « runtime/bin/path_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698