OLD | NEW |
1 /** Support code for the tests in this directory. */ | 1 /** Support code for the tests in this directory. */ |
2 library support; | 2 library support; |
3 | 3 |
4 import 'dart:io'; | 4 import 'dart:io'; |
5 import 'package:html5lib/src/treebuilder.dart'; | 5 import 'package:html5lib/src/treebuilder.dart'; |
6 import 'package:html5lib/dom.dart'; | 6 import 'package:html5lib/dom.dart'; |
7 import 'package:html5lib/dom_parsing.dart'; | 7 import 'package:html5lib/dom_parsing.dart'; |
8 | 8 |
9 typedef TreeBuilder TreeBuilderFactory(bool namespaceHTMLElements); | 9 typedef TreeBuilder TreeBuilderFactory(bool namespaceHTMLElements); |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // it's easier to convert it into an upfront computation. | 53 // it's easier to convert it into an upfront computation. |
54 Iterator<Map> iterator() => _getData().iterator(); | 54 Iterator<Map> iterator() => _getData().iterator(); |
55 | 55 |
56 List<Map> _getData() { | 56 List<Map> _getData() { |
57 var data = <String, String>{}; | 57 var data = <String, String>{}; |
58 var key = null; | 58 var key = null; |
59 var result = <Map>[]; | 59 var result = <Map>[]; |
60 var lines = _text.split('\n'); | 60 var lines = _text.split('\n'); |
61 int numLines = lines.length; | 61 int numLines = lines.length; |
62 // Remove trailing newline to match Python | 62 // Remove trailing newline to match Python |
63 if (lines.last() == '') { | 63 if (lines.last == '') { |
64 lines.removeLast(); | 64 lines.removeLast(); |
65 } | 65 } |
66 for (var line in lines) { | 66 for (var line in lines) { |
67 var heading = sectionHeading(line); | 67 var heading = sectionHeading(line); |
68 if (heading != null) { | 68 if (heading != null) { |
69 if (data.length > 0 && heading == newTestHeading) { | 69 if (data.length > 0 && heading == newTestHeading) { |
70 // Remove trailing newline | 70 // Remove trailing newline |
71 data[key] = data[key].substring(0, data[key].length - 1); | 71 data[key] = data[key].substring(0, data[key].length - 1); |
72 result.add(normaliseOutput(data)); | 72 result.add(normaliseOutput(data)); |
73 data = <String, String>{}; | 73 data = <String, String>{}; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 indent += 1; | 155 indent += 1; |
156 for (var child in node.nodes) visit(child); | 156 for (var child in node.nodes) visit(child); |
157 indent -= 1; | 157 indent -= 1; |
158 } | 158 } |
159 | 159 |
160 visitElement(Element node) { | 160 visitElement(Element node) { |
161 _newline(); | 161 _newline(); |
162 _str.add(node); | 162 _str.add(node); |
163 if (node.attributes.length > 0) { | 163 if (node.attributes.length > 0) { |
164 indent += 2; | 164 indent += 2; |
165 var keys = new List.from(node.attributes.getKeys()); | 165 var keys = new List.from(node.attributes.keys); |
166 keys.sort((x, y) => x.compareTo(y)); | 166 keys.sort((x, y) => x.compareTo(y)); |
167 for (var key in keys) { | 167 for (var key in keys) { |
168 var v = node.attributes[key]; | 168 var v = node.attributes[key]; |
169 if (key is AttributeName) { | 169 if (key is AttributeName) { |
170 AttributeName attr = key; | 170 AttributeName attr = key; |
171 key = "${attr.prefix} ${attr.name}"; | 171 key = "${attr.prefix} ${attr.name}"; |
172 } | 172 } |
173 _newline(); | 173 _newline(); |
174 _str.add('$key="$v"'); | 174 _str.add('$key="$v"'); |
175 } | 175 } |
176 indent -= 2; | 176 indent -= 2; |
177 } | 177 } |
178 visitChildren(node); | 178 visitChildren(node); |
179 } | 179 } |
180 } | 180 } |
OLD | NEW |