| OLD | NEW |
| 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 /** | 5 /** |
| 6 * Tests that we are generating a valid `dart:html` type for each element | 6 * Tests that we are generating a valid `dart:html` type for each element |
| 7 * field. This test is a bit goofy because it needs to run the `dart_analyzer`, | 7 * field. This test is a bit goofy because it needs to run the `dart_analyzer`, |
| 8 * but I can't think of an easier way to validate that the HTML types in our | 8 * but I can't think of an easier way to validate that the HTML types in our |
| 9 * table exist. | 9 * table exist. |
| 10 */ | 10 */ |
| 11 library html_type_test; | 11 library html_type_test; |
| 12 | 12 |
| 13 import 'dart:io'; | 13 import 'dart:io'; |
| 14 import 'package:html5lib/dom.dart'; | 14 import 'package:html5lib/dom.dart'; |
| 15 import 'package:unittest/unittest.dart'; | 15 import 'package:unittest/unittest.dart'; |
| 16 import 'package:unittest/vm_config.dart'; | 16 import 'package:unittest/vm_config.dart'; |
| 17 import 'package:web_components/src/html5_utils.dart'; | 17 import 'package:web_components/src/html5_utils.dart'; |
| 18 import 'package:web_components/src/html5_setters.g.dart'; |
| 18 import 'testing.dart'; | 19 import 'testing.dart'; |
| 19 | 20 |
| 20 main() { | 21 main() { |
| 21 useVmConfiguration(); | 22 useVmConfiguration(); |
| 22 useMockMessages(); | 23 useMockMessages(); |
| 23 | 24 |
| 24 test('types are in dart:html', () { | 25 test('generate type test for tag -> element mapping', () { |
| 25 var code = new StringBuffer(); | 26 var code = new StringBuffer(); |
| 26 code.add('import "dart:html" as html;\n'); | 27 code.add('import "dart:html" as html;\n'); |
| 27 htmlElementNames.forEach((tag, className) { | 28 htmlElementNames.forEach((tag, className) { |
| 28 code.add('html.$className _$tag;\n'); | 29 code.add('html.$className _$tag;\n'); |
| 29 }); | 30 }); |
| 30 | 31 |
| 31 const generatedFile = 'data/output/html5_utils_test_generated.dart'; | 32 // Note: name is important for this to get picked up by run.sh |
| 32 | 33 // We don't analyze here, but run.sh will analyze it. |
| 33 new File(generatedFile).openSync(FileMode.WRITE) | 34 new File('data/output/html5_utils_test_tag_bootstrap.dart') |
| 35 .openSync(FileMode.WRITE) |
| 34 ..writeStringSync(code.toString()) | 36 ..writeStringSync(code.toString()) |
| 35 ..close(); | 37 ..close(); |
| 38 }); |
| 36 | 39 |
| 40 test('generate type test for attribute -> field mapping', () { |
| 41 var code = new StringBuffer(); |
| 42 code.add('import "dart:html" as html;\n'); |
| 43 code.add('main() {\n'); |
| 37 | 44 |
| 38 // TODO(jmesserly): it would be good to run all of our | 45 var allTags = htmlElementNames.keys; |
| 39 // dart_analyzer tests in one batch. | 46 htmlElementFields.forEach((type, attrToField) { |
| 40 Process.run('dart_analyzer', '--fatal-warnings --fatal-type-errors ' | 47 code.add(' html.$type _$type = null;\n'); |
| 41 '--work data/output/analyzer/ $generatedFile'.split(' ')) | 48 for (var field in attrToField.values) { |
| 42 .then(expectAsync1((result) { | 49 code.add('_$type.$field = null;\n'); |
| 43 expect(result.stdout, '', reason: result.stdout); | 50 } |
| 44 expect(result.stderr, '', reason: result.stderr); | 51 }); |
| 45 expect(result.exitCode, 0, | 52 code.add('}\n'); |
| 46 reason: 'expected success, but got exit code ${result.exitCode}'); | 53 |
| 47 })); | 54 // Note: name is important for this to get picked up by run.sh |
| 55 // We don't analyze here, but run.sh will analyze it. |
| 56 new File('data/output/html5_utils_test_attr_bootstrap.dart') |
| 57 .openSync(FileMode.WRITE) |
| 58 ..writeStringSync(code.toString()) |
| 59 ..close(); |
| 48 }); | 60 }); |
| 49 } | 61 } |
| OLD | NEW |