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

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

Issue 303003003: Fix 19029: handle special case when on-handler is empty in polymer, add better (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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/pubspec.yaml ('k') | pkg/polymer/test/build/script_compactor_test.dart » ('j') | 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) 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/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 ]); 316 ]);
317 317
318 group('event handlers', () { 318 group('event handlers', () {
319 _testLinter('onfoo is not polymer', { 319 _testLinter('onfoo is not polymer', {
320 'a|lib/test.html': '''<html><body> 320 'a|lib/test.html': '''<html><body>
321 <div onfoo="something"></div> 321 <div onfoo="something"></div>
322 '''.replaceAll(' ', ''), 322 '''.replaceAll(' ', ''),
323 }, [ 323 }, [
324 'warning: Event handler "onfoo" will be interpreted as an inline ' 324 'warning: Event handler "onfoo" will be interpreted as an inline '
325 'JavaScript event handler. Use the form ' 325 'JavaScript event handler. Use the form '
326 'on-event-name="handlerName" if you want a Dart handler ' 326 'on-event-name="{{handlerName}}" if you want a Dart handler '
327 'that will automatically update the UI based on model changes. ' 327 'that will automatically update the UI based on model changes. '
328 '(lib/test.html 1 5)' 328 '(lib/test.html 1 5)'
329 ]); 329 ]);
330 330
331 _testLinter('on-foo is only supported in polymer elements', { 331 _testLinter('on-foo is only supported in polymer elements', {
332 'a|lib/test.html': '''<html><body> 332 'a|lib/test.html': '''<html><body>
333 <div on-foo="something"></div> 333 <div on-foo="something"></div>
334 '''.replaceAll(' ', ''), 334 '''.replaceAll(' ', ''),
335 }, [ 335 }, [
336 'warning: Inline event handlers are only supported inside ' 336 'warning: Inline event handlers are only supported inside '
337 'declarations of <polymer-element>. ' 337 'declarations of <polymer-element>. '
338 '(lib/test.html 1 5)' 338 '(lib/test.html 1 5)'
339 ]); 339 ]);
340 340
341 _testLinter('on-foo is not an expression', { 341 _testLinter('on-foo is not an expression', {
342 'a|lib/test.html': '''<html><body> 342 'a|lib/test.html': '''<html><body>
343 <polymer-element name="x-a"><div on-foo="bar()"></div> 343 <polymer-element name="x-a"><div on-foo="{{bar()}}"></div>
344 </polymer-element> 344 </polymer-element>
345 '''.replaceAll(' ', ''), 345 '''.replaceAll(' ', ''),
346 }, [ 346 }, [
347 'warning: Invalid event handler body "bar()". Declare a method ' 347 'warning: Invalid event handler body "{{bar()}}". Declare a method '
348 'in your custom element "void handlerName(event, detail, target)" ' 348 'in your custom element "void handlerName(event, detail, target)" '
349 'and use the form on-foo="handlerName". ' 349 'and use the form on-foo="{{handlerName}}". '
350 '(lib/test.html 1 33)'
351 ]);
352
353 _testLinter('on-foo can\'t be empty', {
354 'a|lib/test.html': '''<html><body>
355 <polymer-element name="x-a"><div on-foo="{{}}"></div>
356 </polymer-element>
357 '''.replaceAll(' ', ''),
358 }, [
359 'warning: Invalid event handler body "{{}}". Declare a method '
360 'in your custom element "void handlerName(event, detail, target)" '
361 'and use the form on-foo="{{handlerName}}". '
362 '(lib/test.html 1 33)'
363 ]);
364
365 _testLinter('on-foo can\'t be empty', {
366 'a|lib/test.html': '''<html><body>
367 <polymer-element name="x-a"><div on-foo="{{ }}"></div>
368 </polymer-element>
369 '''.replaceAll(' ', ''),
370 }, [
371 'warning: Invalid event handler body "{{ }}". Declare a method '
372 'in your custom element "void handlerName(event, detail, target)" '
373 'and use the form on-foo="{{handlerName}}". '
350 '(lib/test.html 1 33)' 374 '(lib/test.html 1 33)'
351 ]); 375 ]);
352 376
353 _testLinter('on-foo-bar is supported as a custom event name', { 377 _testLinter('on-foo-bar is supported as a custom event name', {
354 'a|lib/test.html': '''<html><body> 378 'a|lib/test.html': '''<html><body>
355 <polymer-element name="x-a"><div on-foo-bar="quux"></div> 379 <polymer-element name="x-a"><div on-foo-bar="{{quux}}"></div>
356 </polymer-element> 380 </polymer-element>
357 '''.replaceAll(' ', ''), 381 '''.replaceAll(' ', ''),
358 }, []); 382 }, []);
359 }); 383 });
360 384
361 group('using custom tags', () { 385 group('using custom tags', () {
362 _testLinter('tag exists (x-tag)', { 386 _testLinter('tag exists (x-tag)', {
363 'a|lib/test.html': '<x-foo></x-foo>', 387 'a|lib/test.html': '<x-foo></x-foo>',
364 }, [ 388 }, [
365 'warning: definition for Polymer element with tag name "x-foo" not ' 389 'warning: definition for Polymer element with tag name "x-foo" not '
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 515
492 _testLinter(String name, Map inputFiles, List outputMessages, 516 _testLinter(String name, Map inputFiles, List outputMessages,
493 [bool solo = false]) { 517 [bool solo = false]) {
494 var linter = new Linter(new TransformOptions()); 518 var linter = new Linter(new TransformOptions());
495 var outputFiles = {}; 519 var outputFiles = {};
496 if (outputMessages.every((m) => m.startsWith('warning:'))) { 520 if (outputMessages.every((m) => m.startsWith('warning:'))) {
497 inputFiles.forEach((k, v) => outputFiles[k] = v); 521 inputFiles.forEach((k, v) => outputFiles[k] = v);
498 } 522 }
499 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); 523 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo);
500 } 524 }
OLDNEW
« no previous file with comments | « pkg/polymer/pubspec.yaml ('k') | pkg/polymer/test/build/script_compactor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698