| 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 'package:web_components/src/html5_setters.g.dart'; |
| 19 import 'testing.dart'; | 19 import 'testing.dart'; |
| 20 | 20 |
| 21 main() { | 21 main() { |
| 22 useVmConfiguration(); | 22 useVmConfiguration(); |
| 23 useMockMessages(); | 23 useMockMessages(); |
| 24 | 24 |
| 25 test('generate type test for tag -> element mapping', () { | 25 test('generate type test for tag -> element mapping', () { |
| 26 var code = new StringBuffer(); | 26 var code = new StringBuffer(); |
| 27 code.add('import "dart:html" as html;\n'); | 27 code.add('import "dart:html" as html;\n'); |
| 28 code.add('import "dart:web_audio" as web_audio;\n'); |
| 29 code.add('import "dart:svg" as svg;\n'); |
| 28 htmlElementNames.forEach((tag, className) { | 30 htmlElementNames.forEach((tag, className) { |
| 29 code.add('html.$className _$tag;\n'); | 31 code.add('$className _$tag;\n'); |
| 30 }); | 32 }); |
| 31 | 33 |
| 32 // Note: name is important for this to get picked up by run.sh | 34 // Note: name is important for this to get picked up by run.sh |
| 33 // We don't analyze here, but run.sh will analyze it. | 35 // We don't analyze here, but run.sh will analyze it. |
| 34 new File('data/output/html5_utils_test_tag_bootstrap.dart') | 36 new File('data/output/html5_utils_test_tag_bootstrap.dart') |
| 35 .openSync(FileMode.WRITE) | 37 .openSync(FileMode.WRITE) |
| 36 ..writeStringSync(code.toString()) | 38 ..writeStringSync(code.toString()) |
| 37 ..close(); | 39 ..close(); |
| 38 }); | 40 }); |
| 39 | 41 |
| 40 test('generate type test for attribute -> field mapping', () { | 42 test('generate type test for attribute -> field mapping', () { |
| 41 var code = new StringBuffer(); | 43 var code = new StringBuffer(); |
| 42 code.add('import "dart:html" as html;\n'); | 44 code.add('import "dart:html" as html;\n'); |
| 45 code.add('import "dart:web_audio" as web_audio;\n'); |
| 46 code.add('import "dart:svg" as svg;\n'); |
| 43 code.add('main() {\n'); | 47 code.add('main() {\n'); |
| 44 | 48 |
| 45 var allTags = htmlElementNames.keys; | 49 var allTags = htmlElementNames.keys; |
| 46 htmlElementFields.forEach((type, attrToField) { | 50 htmlElementFields.forEach((type, attrToField) { |
| 47 code.add(' html.$type _$type = null;\n'); | 51 var id = type.replaceAll('.', '_'); |
| 52 code.add(' $type _$id = null;\n'); |
| 48 for (var field in attrToField.values) { | 53 for (var field in attrToField.values) { |
| 49 code.add('_$type.$field = null;\n'); | 54 code.add('_$id.$field = null;\n'); |
| 50 } | 55 } |
| 51 }); | 56 }); |
| 52 code.add('}\n'); | 57 code.add('}\n'); |
| 53 | 58 |
| 54 // Note: name is important for this to get picked up by run.sh | 59 // 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. | 60 // We don't analyze here, but run.sh will analyze it. |
| 56 new File('data/output/html5_utils_test_attr_bootstrap.dart') | 61 new File('data/output/html5_utils_test_attr_bootstrap.dart') |
| 57 .openSync(FileMode.WRITE) | 62 .openSync(FileMode.WRITE) |
| 58 ..writeStringSync(code.toString()) | 63 ..writeStringSync(code.toString()) |
| 59 ..close(); | 64 ..close(); |
| 60 }); | 65 }); |
| 61 } | 66 } |
| OLD | NEW |