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

Side by Side Diff: tests/parser_test.dart

Issue 10916294: switch html5lib to new pkg layout (Closed) Base URL: https://github.com/dart-lang/html5lib.git@master
Patch Set: Created 8 years, 3 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
« no previous file with comments | « tests/parser_feature_test.dart ('k') | tests/run.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #library('parser_test');
2
3 #import('dart:io');
4 #import('package:unittest/unittest.dart');
5 #import('package:unittest/vm_config.dart');
6 #import('../lib/constants.dart');
7 #import('../lib/utils.dart');
8 #import('../treebuilders/simpletree.dart');
9 #import('../html5parser.dart');
10 #import('../tokenizer.dart');
11 #import('support.dart');
12
13 // Run the parse error checks
14 // TODO(jmesserly): presumably we want this on by default?
15 final checkParseErrors = false;
16
17 String namespaceHtml(String expected) {
18 // TODO(jmesserly): this is a workaround for http://dartbug.com/2979
19 // We can't do regex replace directly =\
20 // final namespaceExpected = const RegExp(@"^(\s*)<(\S+)>", multiLine: true);
21 // return expected.replaceAll(namespaceExpected, @"$1<html $2>");
22 final namespaceExpected = const RegExp(@"^(\|\s*)<(\S+)>");
23 var lines = expected.split("\n");
24 for (int i = 0; i < lines.length; i++) {
25 var match = namespaceExpected.firstMatch(lines[i]);
26 if (match != null) {
27 lines[i] = "${match[1]}<html ${match[2]}>";
28 }
29 }
30 return Strings.join(lines, "\n");
31 }
32
33 void runParserTest(String groupName, String innerHTML, String input,
34 String expected, List errors, TreeBuilderFactory treeCtor,
35 bool namespaceHTMLElements) {
36
37 // XXX - move this out into the setup function
38 // concatenate all consecutive character tokens into a single token
39 var builder = treeCtor(namespaceHTMLElements);
40 HTMLParser p;
41 try {
42 p = new HTMLParser(builder);
43 } on DataLossWarning catch (w) {
44 return;
45 }
46
47 var document;
48 try {
49 var tokenizer = new HTMLTokenizer(input);
50 if (innerHTML != null) {
51 document = p.parseFragment(tokenizer, container_: innerHTML);
52 } else {
53 try {
54 document = p.parse(tokenizer);
55 } on DataLossWarning catch (w) {
56 return;
57 }
58 }
59 } catch (e, stack) {
60 // TODO(jmesserly): is there a better expect to use here?
61 expect(false, reason: "\n\nInput:\n$input\n\nExpected:\n$expected"
62 "\n\nException:\n$e\n\nStack trace:\n$stack");
63 }
64
65 var output = testSerializer(document);
66
67 if (namespaceHTMLElements) {
68 expected = namespaceHtml(expected);
69 }
70
71 expect(output, equals(expected), reason:
72 "\n\nInput:\n$input\n\nExpected:\n$expected\n\nReceived:\n$output");
73
74 if (checkParseErrors) {
75 expect(p.errors.length, equals(errors.length), reason:
76 "\n\nInput:\n$input\n\nExpected errors (${errors.length}):\n"
77 "${Strings.join(errors, '\n')}\n\nActual errors (${p.errors.length}):\n"
78 "${Strings.join(p.errors.map((e) => '$e'), '\n')}");
79 }
80 }
81
82
83 void main() {
84 useVmConfiguration();
85 getDataFiles('tree-construction').then((files) {
86 for (var path in files) {
87 var tests = new TestData(path, "data");
88 var testName = new Path.fromNative(path).filename.replaceAll(".dat", "");
89
90 group(testName, () {
91 int index = 0;
92 for (var testData in tests) {
93 var input = testData['data'];
94 var errors = testData['errors'];
95 var innerHTML = testData['document-fragment'];
96 var expected = testData['document'];
97 if (errors != null) {
98 errors = errors.split("\n");
99 }
100
101 for (var treeCtor in treeTypes.getValues()) {
102 for (var namespaceHTMLElements in const [false, true]) {
103 test(input, () {
104 runParserTest(testName, innerHTML, input, expected, errors,
105 treeCtor, namespaceHTMLElements);
106 });
107 }
108 }
109
110 index++;
111 }
112 });
113 }
114 });
115 }
OLDNEW
« no previous file with comments | « tests/parser_feature_test.dart ('k') | tests/run.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698