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

Side by Side Diff: utils/tests/pub/path/path_posix_test.dart

Issue 11553005: Move path-manipulation code from io.dart into path.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
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; 5 library path_test;
6 6
7 import 'dart:io' as io; 7 import 'dart:io' as io;
8 8
9 import '../../../../pkg/unittest/lib/unittest.dart'; 9 import '../../../../pkg/unittest/lib/unittest.dart';
10 import '../../../pub/path.dart' as path; 10 import '../../../pub/path.dart' as path;
(...skipping 15 matching lines...) Expand all
26 test('extension', () { 26 test('extension', () {
27 expect(builder.extension(''), ''); 27 expect(builder.extension(''), '');
28 expect(builder.extension('foo.dart'), '.dart'); 28 expect(builder.extension('foo.dart'), '.dart');
29 expect(builder.extension('foo.dart.js'), '.js'); 29 expect(builder.extension('foo.dart.js'), '.js');
30 expect(builder.extension('a.b/c'), ''); 30 expect(builder.extension('a.b/c'), '');
31 expect(builder.extension('a.b/c.d'), '.d'); 31 expect(builder.extension('a.b/c.d'), '.d');
32 expect(builder.extension('~/.bashrc'), ''); 32 expect(builder.extension('~/.bashrc'), '');
33 expect(builder.extension(r'a.b\c'), r'.b\c'); 33 expect(builder.extension(r'a.b\c'), r'.b\c');
34 }); 34 });
35 35
36 test('rootOf', () {
37 expect(builder.rootOf(''), null);
38 expect(builder.rootOf('a'), null);
39 expect(builder.rootOf('a/b'), null);
Bob Nystrom 2012/12/12 00:01:20 I think these should return empty strings.
nweiz 2012/12/12 00:50:37 See other reply.
40 expect(builder.rootOf('/a/c'), '/');
41 expect(builder.rootOf('/'), '/');
42 });
43
44 test('dirname', () {
45 expect(builder.dirname(''), '.');
46 expect(builder.dirname('a'), '.');
47 expect(builder.dirname('a/b'), 'a');
48 expect(builder.dirname('a/b/c'), 'a/b');
49 expect(builder.dirname('a/b.c'), 'a');
50 expect(builder.dirname('a/'), 'a');
51 expect(builder.dirname('a/.'), 'a');
52 expect(builder.dirname(r'a\b/c'), r'a\b');
Bob Nystrom 2012/12/12 00:01:20 Can you add tests for: / -> / a/b/ -> a/b/ (subj
nweiz 2012/12/12 00:50:37 Done.
53 });
54
36 test('basename', () { 55 test('basename', () {
37 expect(builder.basename(''), ''); 56 expect(builder.basename(''), '');
38 expect(builder.basename('a'), 'a'); 57 expect(builder.basename('a'), 'a');
39 expect(builder.basename('a/b'), 'b'); 58 expect(builder.basename('a/b'), 'b');
40 expect(builder.basename('a/b/c'), 'c'); 59 expect(builder.basename('a/b/c'), 'c');
41 expect(builder.basename('a/b.c'), 'b.c'); 60 expect(builder.basename('a/b.c'), 'b.c');
42 expect(builder.basename('a/'), ''); 61 expect(builder.basename('a/'), '');
43 expect(builder.basename('a/.'), '.'); 62 expect(builder.basename('a/.'), '.');
44 expect(builder.basename(r'a/b\c'), r'b\c'); 63 expect(builder.basename(r'a/b\c'), r'b\c');
45 }); 64 });
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'), 116 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
98 'a/b/c/d/e/f/g/h'); 117 'a/b/c/d/e/f/g/h');
99 }); 118 });
100 119
101 test('does not add separator if a part ends in one', () { 120 test('does not add separator if a part ends in one', () {
102 expect(builder.join('a/', 'b', 'c/', 'd'), 'a/b/c/d'); 121 expect(builder.join('a/', 'b', 'c/', 'd'), 'a/b/c/d');
103 expect(builder.join('a\\', 'b'), r'a\/b'); 122 expect(builder.join('a\\', 'b'), r'a\/b');
104 }); 123 });
105 124
106 test('ignores parts before an absolute path', () { 125 test('ignores parts before an absolute path', () {
126 expect(builder.join('a', '/', 'b', 'c'), '/b/c');
107 expect(builder.join('a', '/b', '/c', 'd'), '/c/d'); 127 expect(builder.join('a', '/b', '/c', 'd'), '/c/d');
108 expect(builder.join('a', r'c:\b', 'c', 'd'), r'a/c:\b/c/d'); 128 expect(builder.join('a', r'c:\b', 'c', 'd'), r'a/c:\b/c/d');
109 expect(builder.join('a', r'\\b', 'c', 'd'), r'a/\\b/c/d'); 129 expect(builder.join('a', r'\\b', 'c', 'd'), r'a/\\b/c/d');
110 }); 130 });
131
132 test('ignores trailing nulls', () {
133 expect(builder.join('a', null), equals('a'));
Bob Nystrom 2012/12/12 00:01:20 Do we want to allow join() with no arguments? It c
Bob Nystrom 2012/12/12 00:01:20 Everything else doesn't use explicit equals() here
nweiz 2012/12/12 00:50:37 I don't think so. Given that we don't have a way t
nweiz 2012/12/12 00:50:37 Every other test in Dart (not to mention Pub) uses
Bob Nystrom 2012/12/12 01:02:13 This will get pulled out of pub before too long, s
nweiz 2012/12/12 02:45:57 In everything else we stick with the Dart project
Bob Nystrom 2012/12/12 04:52:33 Sure, if it matters that much to you. In that case
134 expect(builder.join('a', 'b', 'c', null, null), equals('a/b/c'));
135 });
136
137 test('disallows intermediate nulls', () {
138 expect(() => builder.join('a', null, 'b'), throwsArgumentError);
139 expect(() => builder.join(null, 'a'), throwsArgumentError);
140 });
141 });
142
143 group('split', () {
144 test('simple cases', () {
145 expect(builder.split('foo'), equals(['foo']));
146 expect(builder.split('foo/bar'), equals(['foo', 'bar']));
147 expect(builder.split('foo/bar/baz'), equals(['foo', 'bar', 'baz']));
148 expect(builder.split('foo/../bar/./baz'),
149 equals(['foo', '..', 'bar', '.', 'baz']));
150 expect(builder.split('foo//bar///baz'), equals(['foo', 'bar', 'baz']));
151 expect(builder.split('foo/\\/baz'), equals(['foo', '\\', 'baz']));
Bob Nystrom 2012/12/12 00:01:20 Also tests for: . -> . '' -> [] foo/ -> [foo] //
nweiz 2012/12/12 00:50:37 Done.
152 });
153
154 test('includes the root for absolute paths', () {
155 expect(builder.split('/foo/bar/baz'), equals(['/', 'foo', 'bar', 'baz']));
156 expect(builder.split('/'), equals(['/']));
157 });
111 }); 158 });
112 159
113 group('normalize', () { 160 group('normalize', () {
114 test('simple cases', () { 161 test('simple cases', () {
115 expect(builder.normalize(''), ''); 162 expect(builder.normalize(''), '');
116 expect(builder.normalize('.'), '.'); 163 expect(builder.normalize('.'), '.');
117 expect(builder.normalize('..'), '..'); 164 expect(builder.normalize('..'), '..');
118 expect(builder.normalize('a'), 'a'); 165 expect(builder.normalize('a'), 'a');
119 expect(builder.normalize('/'), '/'); 166 expect(builder.normalize('/'), '/');
120 expect(builder.normalize(r'\'), r'\'); 167 expect(builder.normalize(r'\'), r'\');
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 expect(r.relative('a/b.txt'), 'a/b.txt'); 278 expect(r.relative('a/b.txt'), 'a/b.txt');
232 expect(r.relative('../a/b.txt'), '../a/b.txt'); 279 expect(r.relative('../a/b.txt'), '../a/b.txt');
233 expect(r.relative('a/./b/../c.txt'), 'a/c.txt'); 280 expect(r.relative('a/./b/../c.txt'), 'a/c.txt');
234 }); 281 });
235 }); 282 });
236 283
237 test('from a root with extension', () { 284 test('from a root with extension', () {
238 var r = new path.Builder(style: path.Style.posix, root: '/dir.ext'); 285 var r = new path.Builder(style: path.Style.posix, root: '/dir.ext');
239 expect(r.relative('/dir.ext/file'), 'file'); 286 expect(r.relative('/dir.ext/file'), 'file');
240 }); 287 });
288
289 test('with a root parameter', () {
290 expect(builder.relative('/foo/bar/baz', to: '/foo/bar'), equals('baz'));
Bob Nystrom 2012/12/12 00:01:20 This is confusing. Does "to" mean "from" here? Isn
nweiz 2012/12/12 00:50:37 Changed "to" to "base".
291 });
241 }); 292 });
242 293
243 group('resolve', () { 294 group('resolve', () {
244 test('allows up to seven parts', () { 295 test('allows up to seven parts', () {
245 expect(builder.resolve('a'), '/root/path/a'); 296 expect(builder.resolve('a'), '/root/path/a');
246 expect(builder.resolve('a', 'b'), '/root/path/a/b'); 297 expect(builder.resolve('a', 'b'), '/root/path/a/b');
247 expect(builder.resolve('a', 'b', 'c'), '/root/path/a/b/c'); 298 expect(builder.resolve('a', 'b', 'c'), '/root/path/a/b/c');
248 expect(builder.resolve('a', 'b', 'c', 'd'), '/root/path/a/b/c/d'); 299 expect(builder.resolve('a', 'b', 'c', 'd'), '/root/path/a/b/c/d');
249 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), '/root/path/a/b/c/d/e'); 300 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), '/root/path/a/b/c/d/e');
250 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f'), 301 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f'),
(...skipping 24 matching lines...) Expand all
275 expect(builder.withoutExtension('a/'), 'a/'); 326 expect(builder.withoutExtension('a/'), 'a/');
276 expect(builder.withoutExtension('a/b/'), 'a/b/'); 327 expect(builder.withoutExtension('a/b/'), 'a/b/');
277 expect(builder.withoutExtension('a/.'), 'a/.'); 328 expect(builder.withoutExtension('a/.'), 'a/.');
278 expect(builder.withoutExtension('a/.b'), 'a/.b'); 329 expect(builder.withoutExtension('a/.b'), 'a/.b');
279 expect(builder.withoutExtension('a.b/c'), 'a.b/c'); 330 expect(builder.withoutExtension('a.b/c'), 'a.b/c');
280 expect(builder.withoutExtension(r'a.b\c'), r'a'); 331 expect(builder.withoutExtension(r'a.b\c'), r'a');
281 expect(builder.withoutExtension(r'a/b\c'), r'a/b\c'); 332 expect(builder.withoutExtension(r'a/b\c'), r'a/b\c');
282 expect(builder.withoutExtension(r'a/b\c.d'), r'a/b\c'); 333 expect(builder.withoutExtension(r'a/b\c.d'), r'a/b\c');
283 }); 334 });
284 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698