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

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

Issue 11968012: Fix Path.relativeTo and add support for relative paths as input. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: #Just say '/' instead of 'path separator' in the doc comments. Created 7 years, 11 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
« sdk/lib/io/path_impl.dart ('K') | « sdk/lib/io/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();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 testAppend('a/b', '/c/d', 'a/b//c/d'); 176 testAppend('a/b', '/c/d', 'a/b//c/d');
177 testAppend('', 'foo/bar', 'foo/bar'); 177 testAppend('', 'foo/bar', 'foo/bar');
178 testAppend('/foo', '', '/foo/'); 178 testAppend('/foo', '', '/foo/');
179 179
180 // .join can only join a relative path to a path. 180 // .join can only join a relative path to a path.
181 // It cannot join an absolute path to a path. 181 // It cannot join an absolute path to a path.
182 Expect.throws(() => new Path('/a/b/').join(new Path('/c/d'))); 182 Expect.throws(() => new Path('/a/b/').join(new Path('/c/d')));
183 } 183 }
184 184
185 void testRelativeTo() { 185 void testRelativeTo() {
186 // Cases where the arguments are absolute paths.
186 Expect.equals('c/d', 187 Expect.equals('c/d',
187 new Path('/a/b/c/d').relativeTo(new Path('/a/b')).toString()); 188 new Path('/a/b/c/d').relativeTo(new Path('/a/b')).toString());
188 Expect.equals('c/d', 189 Expect.equals('c/d',
189 new Path('/a/b/c/d').relativeTo(new Path('/a/b/')).toString()); 190 new Path('/a/b/c/d').relativeTo(new Path('/a/b/')).toString());
190 Expect.equals('.', 191 Expect.equals('.',
191 new Path('/a').relativeTo(new Path('/a')).toString()); 192 new Path('/a').relativeTo(new Path('/a')).toString());
192 193
193 // Trailing / in base path represents directory 194 // Trailing slash in the base path has no effect. This matches Path.join
195 // semantics, but not URL join semantics.
194 Expect.equals('../../z/x/y', 196 Expect.equals('../../z/x/y',
195 new Path('/a/b/z/x/y').relativeTo(new Path('/a/b/c/d/')).toString()); 197 new Path('/a/b/z/x/y').relativeTo(new Path('/a/b/c/d/')).toString());
196 Expect.equals('../z/x/y', 198 Expect.equals('../../z/x/y',
197 new Path('/a/b/z/x/y').relativeTo(new Path('/a/b/c/d')).toString()); 199 new Path('/a/b/z/x/y').relativeTo(new Path('/a/b/c/d')).toString());
198 Expect.equals('../z/x/y/', 200 Expect.equals('../../z/x/y/',
199 new Path('/a/b/z/x/y/').relativeTo(new Path('/a/b/c/d')).toString()); 201 new Path('/a/b/z/x/y/').relativeTo(new Path('/a/b/c/d')).toString());
200 202
201 Expect.equals('../../z/x/y', 203 Expect.equals('../../../z/x/y',
202 new Path('/z/x/y').relativeTo(new Path('/a/b/c')).toString()); 204 new Path('/z/x/y').relativeTo(new Path('/a/b/c')).toString());
203 Expect.equals('../../../z/x/y', 205 Expect.equals('../../../z/x/y',
204 new Path('/z/x/y').relativeTo(new Path('/a/b/c/')).toString()); 206 new Path('/z/x/y').relativeTo(new Path('/a/b/c/')).toString());
205 207
206 // Not implemented yet. Should return new Path('../b/c/d/'). 208 // Cases where the arguments are relative paths.
207 Expect.throws(() => 209 Expect.equals('c/d',
208 new Path('b/c/d/').relativeTo(new Path('a/'))); 210 new Path('a/b/c/d').relativeTo(new Path('a/b')).toString());
211 Expect.equals('c/d',
212 new Path('/a/b/c/d').relativeTo(new Path('/a/b/')).toString());
213 Expect.equals('.',
214 new Path('a/b/c').relativeTo(new Path('a/b/c')).toString());
215 Expect.equals('.',
216 new Path('').relativeTo(new Path('')).toString());
217 Expect.equals('.',
218 new Path('.').relativeTo(new Path('.')).toString());
219 Expect.equals('a',
220 new Path('a').relativeTo(new Path('.')).toString());
221 Expect.equals('..',
222 new Path('..').relativeTo(new Path('.')).toString());
223 Expect.equals('..',
224 new Path('.').relativeTo(new Path('a')).toString());
225 Expect.equals('.',
226 new Path('..').relativeTo(new Path('..')).toString());
227 Expect.equals('./',
228 new Path('a/b/f/../c/').relativeTo(new Path('a/e/../b/c')).toString());
229 Expect.equals('d',
230 new Path('a/b/f/../c/d').relativeTo(new Path('a/e/../b/c')).toString());
231 Expect.equals('..',
232 new Path('a/b/f/../c').relativeTo(new Path('a/e/../b/c/e/')).toString());
233 Expect.equals('../..',
234 new Path('').relativeTo(new Path('a/b/')).toString());
235 Expect.equals('../../..',
236 new Path('..').relativeTo(new Path('a/b')).toString());
237 Expect.equals('../b/c/d/',
238 new Path('b/c/d/').relativeTo(new Path('a/')).toString());
239
209 // Should always throw - no relative path can be constructed. 240 // Should always throw - no relative path can be constructed.
210 Expect.throws(() => 241 Expect.throws(() =>
211 new Path('a/b').relativeTo(new Path('../../d'))); 242 new Path('a/b').relativeTo(new Path('../../d')));
243 // Should always throw - relative and absolute paths are compared.
244 Expect.throws(() =>
245 new Path('/a/b').relativeTo(new Path('c/d')));
246
247 Expect.throws(() =>
248 new Path('a/b').relativeTo(new Path('/a/b')));
249
212 } 250 }
213 251
214 // Test that Windows share information is maintain through 252 // Test that Windows share information is maintained through
215 // Path operations. 253 // Path operations.
216 void testWindowsShare() { 254 void testWindowsShare() {
217 // Windows share information only makes sense on Windows. 255 // Windows share information only makes sense on Windows.
218 if (Platform.operatingSystem != 'windows') return; 256 if (Platform.operatingSystem != 'windows') return;
219 var path = new Path(r'\\share\a\b\..\c'); 257 var path = new Path(r'\\share\a\b\..\c');
220 Expect.isTrue(path.isAbsolute); 258 Expect.isTrue(path.isAbsolute);
221 Expect.isTrue(path.isWindowsShare); 259 Expect.isTrue(path.isWindowsShare);
222 Expect.isFalse(path.hasTrailingSeparator); 260 Expect.isFalse(path.hasTrailingSeparator);
223 var canonical = path.canonicalize(); 261 var canonical = path.canonicalize();
224 Expect.isTrue(canonical.isAbsolute); 262 Expect.isTrue(canonical.isAbsolute);
(...skipping 11 matching lines...) Expand all
236 Expect.isTrue(canonical.toString().startsWith('/share/a')); 274 Expect.isTrue(canonical.toString().startsWith('/share/a'));
237 Expect.isTrue(canonical.toNativePath().startsWith(r'\\share\a')); 275 Expect.isTrue(canonical.toNativePath().startsWith(r'\\share\a'));
238 Expect.listEquals(['share', 'a', 'c'], canonical.segments()); 276 Expect.listEquals(['share', 'a', 'c'], canonical.segments());
239 var appended = canonical.append('d'); 277 var appended = canonical.append('d');
240 Expect.isTrue(appended.isAbsolute); 278 Expect.isTrue(appended.isAbsolute);
241 Expect.isTrue(appended.isWindowsShare); 279 Expect.isTrue(appended.isWindowsShare);
242 var directoryPath = canonical.directoryPath; 280 var directoryPath = canonical.directoryPath;
243 Expect.isTrue(directoryPath.isAbsolute); 281 Expect.isTrue(directoryPath.isAbsolute);
244 Expect.isTrue(directoryPath.isWindowsShare); 282 Expect.isTrue(directoryPath.isWindowsShare);
245 } 283 }
OLDNEW
« sdk/lib/io/path_impl.dart ('K') | « sdk/lib/io/path_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698