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

Side by Side Diff: test/html5_utils_test.dart

Issue 11315020: Add attribute information table so we generate correct setters. (Closed) Base URL: https://github.com/dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 1 month 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
« lib/src/html5_utils.dart ('K') | « lib/src/html5_utils.dart ('k') | no next file » | 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) 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 'testing.dart'; 18 import 'testing.dart';
19 19
20 main() { 20 main() {
21 useVmConfiguration(); 21 useVmConfiguration();
22 useMockMessages(); 22 useMockMessages();
23 23
24 test('types are in dart:html', () { 24 test('generate type test for tag -> element mapping', () {
25 var code = new StringBuffer(); 25 var code = new StringBuffer();
26 code.add('import "dart:html" as html;\n'); 26 code.add('import "dart:html" as html;\n');
27 htmlElementNames.forEach((tag, className) { 27 htmlElementNames.forEach((tag, className) {
28 code.add('html.$className _$tag;\n'); 28 code.add('html.$className _$tag;\n');
29 }); 29 });
30 30
31 const generatedFile = 'data/output/html5_utils_test_generated.dart'; 31 // Note: name is important for this to get picked up by run.sh
32 new File(generatedFile).openSync(FileMode.WRITE) 32 // We don't analyze here, but run.sh will analyze it.
33 new File('data/output/html5_utils_test_tag_bootstrap.dart')
34 .openSync(FileMode.WRITE)
33 ..writeStringSync(code.toString()) 35 ..writeStringSync(code.toString())
34 ..close(); 36 ..close();
37 });
35 38
36 // TODO(jmesserly): it would be good to run all of our 39 test('generate type test for attribute -> field mapping', () {
37 // dart_analyzer tests in one batch. 40 var code = new StringBuffer();
38 Process.run('dart_analyzer', '--fatal-warnings --fatal-type-errors ' 41 code.add('import "dart:html" as html;\n');
39 '--work data/output/analyzer/ $generatedFile'.split(' ')) 42 code.add('main() {\n');
40 .then(expectAsync1((result) { 43 htmlElementNames.forEach((tag, className) {
41 expect(result.stdout, '', result.stdout); 44 code.add('html.$className _$tag = null;\n');
42 expect(result.stderr, '', result.stderr); 45 });
43 expect(result.exitCode, 0, 'expected success, but got exit code ' 46 var allTags = htmlElementNames.keys;
44 '${result.exitCode}'); 47 htmlAttributeTags.forEach((attr, tags) {
45 })); 48 var renamed = elementFieldRenames[attr];
49 if (renamed != null) attr = renamed;
50
51 if (tags == allHtmlElements) tags = allTags;
52 for (var tag in tags) {
53 code.add('_$tag.$attr = null;\n');
54 }
55 });
56 code.add('}\n');
57
58 // Note: name is important for this to get picked up by run.sh
59 // We don't analyze here, but run.sh will analyze it.
60 new File('data/output/html5_utils_test_attr_bootstrap.dart')
61 .openSync(FileMode.WRITE)
62 ..writeStringSync(code.toString())
63 ..close();
46 }); 64 });
47 } 65 }
OLDNEW
« lib/src/html5_utils.dart ('K') | « lib/src/html5_utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698