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

Side by Side Diff: pkg/polymer/test/build/linter_test.dart

Issue 225043004: Replace bootstrap logic with 'boot.js', use 'component/dart' mime-type and add (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 polymer.test.linter_test; 5 library polymer.test.linter_test;
6 6
7 import 'package:polymer/src/build/common.dart'; 7 import 'package:polymer/src/build/common.dart';
8 import 'package:polymer/src/build/linter.dart'; 8 import 'package:polymer/src/build/linter.dart';
9 import 'package:unittest/compact_vm_config.dart';
10 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
11 10
12 import 'common.dart'; 11 import 'common.dart';
13 12
14 void main() { 13 void main() {
15 useCompactVMConfiguration();
16 _testLinter('nothing to report', { 14 _testLinter('nothing to report', {
17 'a|lib/test.html': '<!DOCTYPE html><html></html>', 15 'a|lib/test.html': '<!DOCTYPE html><html></html>',
18 }, []); 16 }, []);
19 17
20 group('must have Dart code to invoke initPolymer, dart.js, not boot.js', () { 18 group('must have import to polymer.html', () {
21 _testLinter('nothing to report', { 19 _testLinter('nothing to report', {
22 'a|web/test.html': '<!DOCTYPE html><html>' 20 'a|web/test.html': '<!DOCTYPE html><html>'
21 '<link rel="import" href="packages/polymer/polymer.html">'
23 '<script type="application/dart" src="foo.dart">' 22 '<script type="application/dart" src="foo.dart">'
24 '</script>' 23 '</script>'
25 '<script src="packages/browser/dart.js"></script>' 24 '<script src="packages/browser/dart.js"></script>'
26 '</html>', 25 '</html>',
27 }, []); 26 }, []);
28 27
29 _testLinter('missing Dart code and dart.js', { 28 _testLinter('missing everything', {
30 'a|web/test.html': '<!DOCTYPE html><html></html>', 29 'a|web/test.html': '<!DOCTYPE html><html></html>',
31 }, [ 30 }, [
32 'error: $USE_INIT_DART', 31 'warning: $USE_POLYMER_HTML',
33 ]); 32 ]);
34 33
35 _testLinter('using deprecated boot.js', { 34 _testLinter('using deprecated boot.js', {
36 'a|web/test.html': '<!DOCTYPE html><html>\n' 35 'a|web/test.html': '<!DOCTYPE html><html>\n'
37 '<script src="packages/polymer/boot.js"></script>' 36 '<script src="packages/polymer/boot.js"></script>'
38 '<script type="application/dart" src="foo.dart">' 37 '<script type="application/dart" src="foo.dart">'
39 '</script>' 38 '</script>'
40 '<script src="packages/browser/dart.js"></script>' 39 '<script src="packages/browser/dart.js"></script>'
41 '</html>', 40 '</html>',
42 }, [ 41 }, [
43 'warning: $BOOT_JS_DEPRECATED (web/test.html 1 0)', 42 'warning: $USE_POLYMER_HTML',
44 ]); 43 ]);
45 }); 44 });
46 group('single script tag per document', () { 45 group('multiple script tag per document allowed', () {
47 _testLinter('two top-level tags', { 46 _testLinter('two top-level tags', {
48 'a|web/test.html': '<!DOCTYPE html><html>' 47 'a|web/test.html': '<!DOCTYPE html><html>'
48 '<link rel="import" href="packages/polymer/polymer.html">'
49 '<script type="application/dart" src="a.dart">' 49 '<script type="application/dart" src="a.dart">'
50 '</script>\n' 50 '</script>\n'
51 '<script type="application/dart" src="b.dart">' 51 '<script type="application/dart" src="b.dart">'
52 '</script>' 52 '</script>'
53 '<script src="packages/browser/dart.js"></script>' 53 '<script src="packages/browser/dart.js"></script>'
54 }, [ 54 }, []);
55 'warning: Only one "application/dart" script tag per document is'
56 ' allowed. (web/test.html 1 0)',
57 ]);
58
59 _testLinter('two top-level tags, non entrypoint', {
60 'a|lib/test.html': '<!DOCTYPE html><html>'
61 '<script type="application/dart" src="a.dart">'
62 '</script>\n'
63 '<script type="application/dart" src="b.dart">'
64 '</script>'
65 '<script src="packages/browser/dart.js"></script>'
66 }, [
67 'warning: Only one "application/dart" script tag per document is'
68 ' allowed. (lib/test.html 1 0)',
69 ]);
70 55
71 _testLinter('tags inside elements', { 56 _testLinter('tags inside elements', {
72 'a|web/test.html': '<!DOCTYPE html><html>' 57 'a|web/test.html': '<!DOCTYPE html><html>'
58 '<link rel="import" href="packages/polymer/polymer.html">'
73 '<polymer-element name="x-a">' 59 '<polymer-element name="x-a">'
74 '<script type="application/dart" src="a.dart">' 60 '<script type="application/dart" src="a.dart">'
75 '</script>' 61 '</script>'
76 '</polymer-element>\n' 62 '</polymer-element>\n'
77 '<script type="application/dart" src="b.dart">' 63 '<script type="application/dart" src="b.dart">'
78 '</script>' 64 '</script>'
79 '<script src="packages/browser/dart.js"></script>' 65 '<script src="packages/browser/dart.js"></script>'
80 }, [ 66 }, []);
81 'warning: Only one "application/dart" script tag per document is'
82 ' allowed. (web/test.html 1 0)',
83 ]);
84 }); 67 });
85 68
86 group('doctype warning', () { 69 group('doctype warning', () {
87 _testLinter('in web', { 70 _testLinter('in web', {
88 'a|web/test.html': '<html></html>', 71 'a|web/test.html': '<html></html>',
89 }, [ 72 }, [
90 'warning: Unexpected start tag (html). Expected DOCTYPE. ' 73 'warning: Unexpected start tag (html). Expected DOCTYPE. '
91 '(web/test.html 0 0)', 74 '(web/test.html 0 0)',
92 'error: $USE_INIT_DART', 75 'warning: $USE_POLYMER_HTML',
93 ]); 76 ]);
94 77
95 _testLinter('in lib', { 78 _testLinter('in lib', {
96 'a|lib/test.html': '<html></html>', 79 'a|lib/test.html': '<html></html>',
97 }, []); 80 }, []);
98 }); 81 });
99 82
100 group('duplicate polymer-elements,', () { 83 group('duplicate polymer-elements,', () {
101 _testLinter('same file', { 84 _testLinter('same file', {
102 'a|lib/test.html': '''<html> 85 'a|lib/test.html': '''<html>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 'warning: custom element with name "x-b" not found. (lib/test.html 1 0)' 203 'warning: custom element with name "x-b" not found. (lib/test.html 1 0)'
221 ]); 204 ]);
222 205
223 206
224 group('script type matches code', () { 207 group('script type matches code', () {
225 _testLinter('top-level, .dart url', { 208 _testLinter('top-level, .dart url', {
226 'a|lib/test.html': '''<html> 209 'a|lib/test.html': '''<html>
227 <script src="foo.dart"></script> 210 <script src="foo.dart"></script>
228 </html>'''.replaceAll(' ', ''), 211 </html>'''.replaceAll(' ', ''),
229 }, [ 212 }, [
230 'warning: Wrong script type, expected type="application/dart".' 213 'warning: Wrong script type, expected type="application/dart" or'
231 ' (lib/test.html 1 0)' 214 ' type="application/dart;component=1". (lib/test.html 1 0)'
232 ]); 215 ]);
233 216
234 _testLinter('in polymer-element, .dart url', { 217 _testLinter('in polymer-element, .dart url', {
235 'a|lib/test.html': '''<html> 218 'a|lib/test.html': '''<html>
236 <polymer-element name="x-a"> 219 <polymer-element name="x-a">
237 <script src="foo.dart"></script> 220 <script src="foo.dart"></script>
238 </polymer-element> 221 </polymer-element>
239 </html>'''.replaceAll(' ', ''), 222 </html>'''.replaceAll(' ', ''),
240 }, [ 223 }, [
241 'warning: Wrong script type, expected type="application/dart".' 224 'warning: Wrong script type, expected type="application/dart" or'
242 ' (lib/test.html 2 0)' 225 ' type="application/dart;component=1". (lib/test.html 2 0)'
243 ]); 226 ]);
244 227
245 _testLinter('in polymer-element, .js url', { 228 _testLinter('in polymer-element, .js url', {
246 'a|lib/test.html': '''<html> 229 'a|lib/test.html': '''<html>
247 <polymer-element name="x-a"> 230 <polymer-element name="x-a">
248 <script src="foo.js"></script> 231 <script src="foo.js"></script>
249 </polymer-element> 232 </polymer-element>
250 </html>'''.replaceAll(' ', ''), 233 </html>'''.replaceAll(' ', ''),
251 }, []); 234 }, []);
252 235
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 }); 433 });
451 434
452 _testLinter("namespaced attributes don't cause an internal error", { 435 _testLinter("namespaced attributes don't cause an internal error", {
453 'a|lib/test.html': '''<html><body> 436 'a|lib/test.html': '''<html><body>
454 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> 437 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350">
455 </svg> 438 </svg>
456 '''.replaceAll(' ', ''), 439 '''.replaceAll(' ', ''),
457 }, []); 440 }, []);
458 } 441 }
459 442
460 _testLinter(String name, Map inputFiles, List outputMessages) { 443 _testLinter(String name, Map inputFiles, List outputMessages,
444 [bool solo = false]) {
461 var linter = new Linter(new TransformOptions()); 445 var linter = new Linter(new TransformOptions());
462 var outputFiles = {}; 446 var outputFiles = {};
463 if (outputMessages.every((m) => m.startsWith('warning:'))) { 447 if (outputMessages.every((m) => m.startsWith('warning:'))) {
464 inputFiles.forEach((k, v) => outputFiles[k] = v); 448 inputFiles.forEach((k, v) => outputFiles[k] = v);
465 } 449 }
466 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages); 450 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo);
467 } 451 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698