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

Side by Side Diff: pkg/polymer/test/paths_test.dart

Issue 23224003: move polymer.dart into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add --deploy to todomvc sample Created 7 years, 4 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 | « pkg/polymer/test/data/unit/events_test.html ('k') | pkg/polymer/test/run.sh » ('j') | 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 /** Tests for [PathMapper]. */
6 library path_info_test;
7
8 import 'package:path/path.dart' as path;
9 import 'package:unittest/compact_vm_config.dart';
10 import 'package:unittest/unittest.dart';
11 import 'package:polymer/src/info.dart';
12 import 'package:polymer/src/paths.dart';
13 import 'package:polymer/src/utils.dart' as utils;
14
15 main() {
16 useCompactVMConfiguration();
17 group('outdir == basedir:', () {
18 group('outputPath', () {
19 test('mangle automatic', () {
20 var pathMapper = _newPathMapper('a', 'a', false);
21 var file = _mockFile('a/b.dart', pathMapper);
22 expect(file.dartCodeUrl.resolvedPath, 'a/b.dart');
23 expect(pathMapper.outputPath(file.dartCodeUrl.resolvedPath, '.dart'),
24 'a/_b.dart.dart');
25 });
26
27 test('within packages/', () {
28 var pathMapper = _newPathMapper('a', 'a', false);
29 var file = _mockFile('a/packages/b.dart', pathMapper);
30 expect(file.dartCodeUrl.resolvedPath, 'a/packages/b.dart');
31 expect(pathMapper.outputPath(file.dartCodeUrl.resolvedPath, '.dart'),
32 'a/_from_packages/_b.dart.dart');
33 });
34 });
35
36 group('importUrlFor', () {
37 test('simple pathMapper', () {
38 var pathMapper = _newPathMapper('a', 'a', false);
39 var file1 = _mockFile('a/b.dart', pathMapper);
40 var file2 = _mockFile('a/c/d.dart', pathMapper);
41 var file3 = _mockFile('a/e/f.dart', pathMapper);
42 expect(pathMapper.importUrlFor(file1, file2), 'c/_d.dart.dart');
43 expect(pathMapper.importUrlFor(file1, file3), 'e/_f.dart.dart');
44 expect(pathMapper.importUrlFor(file2, file1), '../_b.dart.dart');
45 expect(pathMapper.importUrlFor(file2, file3), '../e/_f.dart.dart');
46 expect(pathMapper.importUrlFor(file3, file2), '../c/_d.dart.dart');
47 expect(pathMapper.importUrlFor(file3, file1), '../_b.dart.dart');
48 });
49
50 test('include packages/', () {
51 var pathMapper = _newPathMapper('a', 'a', false);
52 var file1 = _mockFile('a/b.dart', pathMapper);
53 var file2 = _mockFile('a/c/d.dart', pathMapper);
54 var file3 = _mockFile('a/packages/f.dart', pathMapper);
55 expect(pathMapper.importUrlFor(file1, file2), 'c/_d.dart.dart');
56 expect(pathMapper.importUrlFor(file1, file3),
57 '_from_packages/_f.dart.dart');
58 expect(pathMapper.importUrlFor(file2, file1), '../_b.dart.dart');
59 expect(pathMapper.importUrlFor(file2, file3),
60 '../_from_packages/_f.dart.dart');
61 expect(pathMapper.importUrlFor(file3, file2), '../c/_d.dart.dart');
62 expect(pathMapper.importUrlFor(file3, file1), '../_b.dart.dart');
63 });
64
65 test('packages, but no rewrite', () {
66 var pathMapper = _newPathMapper('a', 'a', false, rewriteUrls: false);
67 var file1 = _mockFile('a/b.dart', pathMapper);
68 var file2 = _mockFile('a/c/d.dart', pathMapper);
69 var file3 = _mockFile('a/packages/c/f.dart', pathMapper,
70 url: 'package:e/f.dart');
71 expect(pathMapper.importUrlFor(file1, file2), 'c/_d.dart.dart');
72 expect(pathMapper.importUrlFor(file1, file3),
73 'package:e/_f.dart.dart');
74 expect(pathMapper.importUrlFor(file2, file1), '../_b.dart.dart');
75 expect(pathMapper.importUrlFor(file2, file3),
76 'package:e/_f.dart.dart');
77 });
78
79 test('windows paths', () {
80 try {
81 utils.path = new path.Builder(style: path.Style.windows);
82 var pathMapper = _newPathMapper('a', 'a', false);
83 var file1 = _mockFile('a\\b.dart', pathMapper);
84 var file2 = _mockFile('a\\c\\d.dart', pathMapper);
85 var file3 = _mockFile('a\\packages\\f.dart', pathMapper);
86 expect(pathMapper.importUrlFor(file1, file2), 'c/_d.dart.dart');
87 expect(pathMapper.importUrlFor(file1, file3),
88 '_from_packages/_f.dart.dart');
89 expect(pathMapper.importUrlFor(file2, file1), '../_b.dart.dart');
90 expect(pathMapper.importUrlFor(file2, file3),
91 '../_from_packages/_f.dart.dart');
92 expect(pathMapper.importUrlFor(file3, file2), '../c/_d.dart.dart');
93 expect(pathMapper.importUrlFor(file3, file1), '../_b.dart.dart');
94 } finally {
95 utils.path = new path.Builder();
96 }
97 });
98 });
99
100 test('transformUrl simple paths', () {
101 var pathMapper = _newPathMapper('a', 'a', false);
102 var file1 = 'a/b.dart';
103 var file2 = 'a/c/d.html';
104 // when the output == input directory, no paths should be rewritten
105 expect(pathMapper.transformUrl(file1, '/a.dart'), '/a.dart');
106 expect(pathMapper.transformUrl(file1, 'c.dart'), 'c.dart');
107 expect(pathMapper.transformUrl(file1, '../c/d.dart'), '../c/d.dart');
108 expect(pathMapper.transformUrl(file1, 'packages/c.dart'),
109 'packages/c.dart');
110 expect(pathMapper.transformUrl(file2, 'e.css'), 'e.css');
111 expect(pathMapper.transformUrl(file2, '../c/e.css'), 'e.css');
112 expect(pathMapper.transformUrl(file2, '../q/e.css'), '../q/e.css');
113 expect(pathMapper.transformUrl(file2, 'packages/c.css'),
114 'packages/c.css');
115 expect(pathMapper.transformUrl(file2, '../packages/c.css'),
116 '../packages/c.css');
117 });
118
119 test('transformUrl with source in packages/', () {
120 var pathMapper = _newPathMapper('a', 'a', false);
121 var file = 'a/packages/e.html';
122 // Even when output == base, files under packages/ are moved to
123 // _from_packages, so all imports are affected:
124 expect(pathMapper.transformUrl(file, 'e.css'), '../packages/e.css');
125 expect(pathMapper.transformUrl(file, '../packages/e.css'),
126 '../packages/e.css');
127 expect(pathMapper.transformUrl(file, '../q/e.css'), '../q/e.css');
128 expect(pathMapper.transformUrl(file, 'packages/c.css'),
129 '../packages/packages/c.css');
130 });
131 });
132
133 group('outdir != basedir:', () {
134 group('outputPath', (){
135 test('no force mangle', () {
136 var pathMapper = _newPathMapper('a', 'out', false);
137 var file = _mockFile('a/b.dart', pathMapper);
138 expect(file.dartCodeUrl.resolvedPath, 'a/b.dart');
139 expect(pathMapper.outputPath(file.dartCodeUrl.resolvedPath, '.dart'),
140 'out/b.dart');
141 });
142
143 test('force mangling', () {
144 var pathMapper = _newPathMapper('a', 'out', true);
145 var file = _mockFile('a/b.dart', pathMapper);
146 expect(file.dartCodeUrl.resolvedPath, 'a/b.dart');
147 expect(pathMapper.outputPath(file.dartCodeUrl.resolvedPath, '.dart'),
148 'out/_b.dart.dart');
149 });
150
151 test('within packages/, no mangle', () {
152 var pathMapper = _newPathMapper('a', 'out', false);
153 var file = _mockFile('a/packages/b.dart', pathMapper);
154 expect(file.dartCodeUrl.resolvedPath, 'a/packages/b.dart');
155 expect(pathMapper.outputPath(file.dartCodeUrl.resolvedPath, '.dart'),
156 'out/_from_packages/b.dart');
157 });
158
159 test('within packages/, mangle', () {
160 var pathMapper = _newPathMapper('a', 'out', true);
161 var file = _mockFile('a/packages/b.dart', pathMapper);
162 expect(file.dartCodeUrl.resolvedPath, 'a/packages/b.dart');
163 expect(pathMapper.outputPath(file.dartCodeUrl.resolvedPath, '.dart'),
164 'out/_from_packages/_b.dart.dart');
165 });
166 });
167
168 group('importUrlFor', (){
169 test('simple paths, no mangle', () {
170 var pathMapper = _newPathMapper('a', 'out', false);
171 var file1 = _mockFile('a/b.dart', pathMapper);
172 var file2 = _mockFile('a/c/d.dart', pathMapper);
173 var file3 = _mockFile('a/e/f.dart', pathMapper);
174 expect(pathMapper.importUrlFor(file1, file2), 'c/d.dart');
175 expect(pathMapper.importUrlFor(file1, file3), 'e/f.dart');
176 expect(pathMapper.importUrlFor(file2, file1), '../b.dart');
177 expect(pathMapper.importUrlFor(file2, file3), '../e/f.dart');
178 expect(pathMapper.importUrlFor(file3, file2), '../c/d.dart');
179 expect(pathMapper.importUrlFor(file3, file1), '../b.dart');
180 });
181
182 test('simple paths, mangle', () {
183 var pathMapper = _newPathMapper('a', 'out', true);
184 var file1 = _mockFile('a/b.dart', pathMapper);
185 var file2 = _mockFile('a/c/d.dart', pathMapper);
186 var file3 = _mockFile('a/e/f.dart', pathMapper);
187 expect(pathMapper.importUrlFor(file1, file2), 'c/_d.dart.dart');
188 expect(pathMapper.importUrlFor(file1, file3), 'e/_f.dart.dart');
189 expect(pathMapper.importUrlFor(file2, file1), '../_b.dart.dart');
190 expect(pathMapper.importUrlFor(file2, file3), '../e/_f.dart.dart');
191 expect(pathMapper.importUrlFor(file3, file2), '../c/_d.dart.dart');
192 expect(pathMapper.importUrlFor(file3, file1), '../_b.dart.dart');
193 });
194
195 test('include packages/, no mangle', () {
196 var pathMapper = _newPathMapper('a', 'out', false);
197 var file1 = _mockFile('a/b.dart', pathMapper);
198 var file2 = _mockFile('a/c/d.dart', pathMapper);
199 var file3 = _mockFile('a/packages/e/f.dart', pathMapper,
200 url: 'package:e/f.dart');
201 expect(pathMapper.importUrlFor(file1, file2), 'c/d.dart');
202 expect(pathMapper.importUrlFor(file1, file3),
203 '_from_packages/e/f.dart');
204 expect(pathMapper.importUrlFor(file2, file1), '../b.dart');
205 expect(pathMapper.importUrlFor(file2, file3),
206 '../_from_packages/e/f.dart');
207 expect(pathMapper.importUrlFor(file3, file2), '../../c/d.dart');
208 expect(pathMapper.importUrlFor(file3, file1), '../../b.dart');
209 });
210
211 test('include packages/, mangle', () {
212 var pathMapper = _newPathMapper('a', 'out', true);
213 var file1 = _mockFile('a/b.dart', pathMapper);
214 var file2 = _mockFile('a/c/d.dart', pathMapper);
215 var file3 = _mockFile('a/packages/e/f.dart', pathMapper,
216 url: 'package:e/f.dart');
217 expect(pathMapper.importUrlFor(file1, file2), 'c/_d.dart.dart');
218 expect(pathMapper.importUrlFor(file1, file3),
219 '_from_packages/e/_f.dart.dart');
220 expect(pathMapper.importUrlFor(file2, file1), '../_b.dart.dart');
221 expect(pathMapper.importUrlFor(file2, file3),
222 '../_from_packages/e/_f.dart.dart');
223 expect(pathMapper.importUrlFor(file3, file2), '../../c/_d.dart.dart');
224 expect(pathMapper.importUrlFor(file3, file1), '../../_b.dart.dart');
225 });
226
227 test('windows paths', () {
228 try {
229 utils.path = new path.Builder(style: path.Style.windows);
230 var pathMapper = _newPathMapper('a', 'out', true);
231 var file1 = _mockFile('a\\b.dart', pathMapper);
232 var file2 = _mockFile('a\\c\\d.dart', pathMapper);
233 var file3 = _mockFile('a\\packages\\f.dart', pathMapper);
234 expect(pathMapper.importUrlFor(file1, file2), 'c/_d.dart.dart');
235 expect(pathMapper.importUrlFor(file1, file3),
236 '_from_packages/_f.dart.dart');
237 expect(pathMapper.importUrlFor(file2, file1), '../_b.dart.dart');
238 expect(pathMapper.importUrlFor(file2, file3),
239 '../_from_packages/_f.dart.dart');
240 expect(pathMapper.importUrlFor(file3, file2), '../c/_d.dart.dart');
241 expect(pathMapper.importUrlFor(file3, file1), '../_b.dart.dart');
242 } finally {
243 utils.path = new path.Builder();
244 }
245 });
246 });
247
248 group('transformUrl', () {
249 test('simple source, not in packages/', () {
250 var pathMapper = _newPathMapper('a', 'out', false);
251 var file1 = 'a/b.dart';
252 var file2 = 'a/c/d.html';
253 // when the output == input directory, no paths should be rewritten
254 expect(pathMapper.transformUrl(file1, '/a.dart'), '/a.dart');
255 expect(pathMapper.transformUrl(file1, 'c.dart'), '../a/c.dart');
256
257 // reach out from basedir:
258 expect(pathMapper.transformUrl(file1, '../c/d.dart'), '../c/d.dart');
259
260 // reach into packages dir:
261 expect(pathMapper.transformUrl(file1, 'packages/c.dart'),
262 '../a/packages/c.dart');
263
264 expect(pathMapper.transformUrl(file2, 'e.css'), '../../a/c/e.css');
265
266 _checkPath('../../a/c/../c/e.css', '../../a/c/e.css');
267 expect(pathMapper.transformUrl(file2, '../c/e.css'), '../../a/c/e.css');
268
269 _checkPath('../../a/c/../q/e.css', '../../a/q/e.css');
270 expect(pathMapper.transformUrl(file2, '../q/e.css'), '../../a/q/e.css');
271
272 expect(pathMapper.transformUrl(file2, 'packages/c.css'),
273 '../../a/c/packages/c.css');
274 _checkPath('../../a/c/../packages/c.css', '../../a/packages/c.css');
275 expect(pathMapper.transformUrl(file2, '../packages/c.css'),
276 '../../a/packages/c.css');
277 });
278
279 test('input in packages/', () {
280 var pathMapper = _newPathMapper('a', 'out', true);
281 var file = 'a/packages/e.html';
282 expect(pathMapper.transformUrl(file, 'e.css'),
283 '../../a/packages/e.css');
284 expect(pathMapper.transformUrl(file, '../packages/e.css'),
285 '../../a/packages/e.css');
286 expect(pathMapper.transformUrl(file, '../q/e.css'), '../../a/q/e.css');
287 expect(pathMapper.transformUrl(file, 'packages/c.css'),
288 '../../a/packages/packages/c.css');
289 });
290
291 test('src fragments', () {
292 var pathMapper = _newPathMapper('a', 'out', false);
293 var file1 = 'a/b.dart';
294 var file2 = 'a/c/html.html';
295 // when the output == input directory, no paths should be rewritten
296 expect(pathMapper.transformUrl(file1, '#tips'), '#tips');
297 expect(pathMapper.transformUrl(file1,
298 'http://www.w3schools.com/html_links.htm#tips'),
299 'http://www.w3schools.com/html_links.htm#tips');
300 expect(pathMapper.transformUrl(file2,
301 'html_links.html'),
302 '../../a/c/html_links.html');
303 expect(pathMapper.transformUrl(file2,
304 'html_links.html#tips'),
305 '../../a/c/html_links.html#tips');
306 });
307 });
308 });
309 }
310
311 _newPathMapper(String baseDir, String outDir, bool forceMangle,
312 {bool rewriteUrls: true}) =>
313 new PathMapper(baseDir, outDir, 'packages', forceMangle, rewriteUrls);
314
315 _mockFile(String filePath, PathMapper pathMapper, {String url}) {
316 var file = new FileInfo(new UrlInfo(
317 url == null ? filePath : url, filePath, null));
318 file.outputFilename = pathMapper.mangle(
319 utils.path.basename(filePath), '.dart', false);
320 return file;
321 }
322
323 _checkPath(String filePath, String expected) {
324 expect(utils.path.normalize(filePath), expected);
325 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/data/unit/events_test.html ('k') | pkg/polymer/test/run.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698