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

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

Issue 11087034: Fixing path.relativeTo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changing hasTrailingSeparator. Created 8 years, 2 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
« no previous file with comments | « 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
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 // Test the Path class in dart:io. 5 // Test the Path class in dart:io.
6 6
7 #import("dart:io"); 7 #import("dart:io");
8 8
9 void main() { 9 void main() {
10 testBaseFunctions(); 10 testBaseFunctions();
11 testCanonicalize(); 11 testCanonicalize();
12 testJoinAppend(); 12 testJoinAppend();
13 testRelativeTo();
13 } 14 }
14 15
15 void testBaseFunctions() { 16 void testBaseFunctions() {
16 testGetters(new Path("/foo/bar/fisk.hest"), 17 testGetters(new Path("/foo/bar/fisk.hest"),
17 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], 18 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'],
18 'absolute canonical'); 19 'absolute canonical');
19 testGetters(new Path(''), 20 testGetters(new Path(''),
20 ['', '', '', ''], 21 ['', '', '', ''],
21 'empty'); 22 'empty');
22 // This corner case leaves a trailing slash for the root. 23 // This corner case leaves a trailing slash for the root.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 testAppend('/a/b', 'c', '/a/b/c'); 157 testAppend('/a/b', 'c', '/a/b/c');
157 testAppend('a/b/', 'cd', 'a/b/cd'); 158 testAppend('a/b/', 'cd', 'a/b/cd');
158 testAppend('.', '..', './..'); 159 testAppend('.', '..', './..');
159 testAppend('a/b', '/c/d', 'a/b//c/d'); 160 testAppend('a/b', '/c/d', 'a/b//c/d');
160 testAppend('', 'foo/bar', 'foo/bar'); 161 testAppend('', 'foo/bar', 'foo/bar');
161 testAppend('/foo', '', '/foo/'); 162 testAppend('/foo', '', '/foo/');
162 163
163 // .join can only join a relative path to a path. 164 // .join can only join a relative path to a path.
164 // It cannot join an absolute path to a path. 165 // It cannot join an absolute path to a path.
165 Expect.throws(() => new Path('/a/b/').join(new Path('/c/d'))); 166 Expect.throws(() => new Path('/a/b/').join(new Path('/c/d')));
167 }
166 168
167 // Test Path.relativeTo. 169 void testRelativeTo() {
168 Expect.equals('c/d', 170 Expect.equals('c/d',
169 new Path('/a/b/c/d').relativeTo(new Path('/a/b')).toString()); 171 new Path('/a/b/c/d').relativeTo(new Path('/a/b')).toString());
170 Expect.equals('c/d', 172 Expect.equals('c/d',
171 new Path('/a/b/c/d').relativeTo(new Path('/a/b/')).toString()); 173 new Path('/a/b/c/d').relativeTo(new Path('/a/b/')).toString());
172 Expect.equals('.', 174 Expect.equals('.',
173 new Path('/a').relativeTo(new Path('/a')).toString()); 175 new Path('/a').relativeTo(new Path('/a')).toString());
174 176
177 // Trailing / in base path represents directory
178 Expect.equals('../../z/x/y',
179 new Path('/a/b/z/x/y').relativeTo(new Path('/a/b/c/d/')).toString());
180 Expect.equals('../z/x/y',
181 new Path('/a/b/z/x/y').relativeTo(new Path('/a/b/c/d')).toString());
182 Expect.equals('../z/x/y/',
183 new Path('/a/b/z/x/y/').relativeTo(new Path('/a/b/c/d')).toString());
184
185 Expect.equals('../../z/x/y',
186 new Path('/z/x/y').relativeTo(new Path('/a/b/c')).toString());
187 Expect.equals('../../../z/x/y',
188 new Path('/z/x/y').relativeTo(new Path('/a/b/c/')).toString());
189
175 // Not implemented yet. Should return new Path('../b/c/d/'). 190 // Not implemented yet. Should return new Path('../b/c/d/').
176 Expect.throws(() => 191 Expect.throws(() =>
177 new Path('b/c/d/').relativeTo(new Path('a/'))); 192 new Path('b/c/d/').relativeTo(new Path('a/')));
178 // Should always throw - no relative path can be constructed. 193 // Should always throw - no relative path can be constructed.
179 Expect.throws(() => 194 Expect.throws(() =>
180 new Path('a/b').relativeTo(new Path('../../d'))); 195 new Path('a/b').relativeTo(new Path('../../d')));
181 } 196 }
OLDNEW
« no previous file with comments | « runtime/bin/path_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698