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

Unified Diff: tests/support.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/run.sh ('k') | tests/tokenizer_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/support.dart
diff --git a/tests/support.dart b/tests/support.dart
deleted file mode 100644
index d3be471b8f12835ef0a3e9a9b0d56ed7b8b5e77d..0000000000000000000000000000000000000000
--- a/tests/support.dart
+++ /dev/null
@@ -1,179 +0,0 @@
-/** Support code for the tests in this directory. */
-#library('support');
-
-#import('dart:io');
-#import('../treebuilders/base.dart');
-#import('../treebuilders/simpletree.dart');
-
-typedef TreeBuilder TreeBuilderFactory(bool namespaceHTMLElements);
-
-Map _treeTypes;
-Map<String, TreeBuilderFactory> get treeTypes {
- if (_treeTypes == null) {
- // TODO(jmesserly): add DOM here once it's implemented
- _treeTypes = { "simpletree": (useNs) => new TreeBuilder(useNs) };
- }
- return _treeTypes;
-}
-
-final testDataDir = '';
-
-typedef bool FileMatcher(String fileName);
-
-Future<List<String>> getDataFiles(String subdirectory, [FileMatcher matcher]) {
- if (matcher == null) matcher = (path) => path.endsWith('.dat');
-
- // TODO(jmesserly): should have listSync for scripting...
- // This entire method was one line of Python code
- var dir = new Directory.fromPath(new Path('tests/data/$subdirectory'));
- var lister = dir.list();
- var files = <String>[];
- lister.onFile = (file) {
- if (matcher(file)) files.add(file);
- };
- var completer = new Completer<List<String>>();
- lister.onDone = (success) {
- completer.complete(files);
- };
- return completer.future;
-}
-
-// TODO(jmesserly): make this class simpler. We could probably split on
-// "\n#" instead of newline and remove a lot of code.
-class TestData implements Iterable<Map> {
- final String _text;
- final String newTestHeading;
-
- TestData(String filename, [this.newTestHeading = "data"])
- // Note: can't use readAsLinesSync here because it splits on \r
- : _text = new File(filename).readAsTextSync();
-
- // Note: in Python this was a generator, but since we can't do that in Dart,
- // it's easier to convert it into an upfront computation.
- Iterator<Map> iterator() => _getData().iterator();
-
- List<Map> _getData() {
- var data = <String, String>{};
- var key = null;
- var result = <Map>[];
- var lines = _text.split('\n');
- int numLines = lines.length;
- // Remove trailing newline to match Python
- if (lines.last() == '') {
- lines.removeLast();
- }
- for (var line in lines) {
- var heading = sectionHeading(line);
- if (heading != null) {
- if (data.length > 0 && heading == newTestHeading) {
- // Remove trailing newline
- data[key] = data[key].substring(0, data[key].length - 1);
- result.add(normaliseOutput(data));
- data = <String, String>{};
- }
- key = heading;
- data[key] = "";
- } else if (key != null) {
- data[key] = '${data[key]}$line\n';
- }
- }
-
- if (data.length > 0) {
- result.add(normaliseOutput(data));
- }
- return result;
- }
-
- /**
- * If the current heading is a test section heading return the heading,
- * otherwise return null.
- */
- static String sectionHeading(String line) {
- return line.startsWith("#") ? line.substring(1).trim() : null;
- }
-
- static Map normaliseOutput(Map data) {
- // Remove trailing newlines
- data.forEach((key, value) {
- if (value.endsWith("\n")) {
- data[key] = value.substring(0, value.length - 1);
- }
- });
- return data;
- }
-}
-
-/**
- * Serialize the [document] into the html5 test data format.
- */
-testSerializer(Document document) {
- return (new TestSerializer()..visit(document)).toString();
-}
-
-/** Serializes the DOM into test format. See [testSerializer]. */
-class TestSerializer extends TreeVisitor {
- final StringBuffer _str;
- int _indent = 0;
- String _spaces = '';
-
- TestSerializer() : _str = new StringBuffer();
-
- String toString() => _str.toString();
-
- int get indent => _indent;
-
- set indent(int value) {
- if (_indent == value) return;
-
- var arr = new List<int>(value);
- for (int i = 0; i < value; i++) {
- arr[i] = 32;
- }
- _spaces = new String.fromCharCodes(arr);
- _indent = value;
- }
-
- void _newline() {
- if (_str.length > 0) _str.add('\n');
- _str.add('|$_spaces');
- }
-
- visitNodeFallback(Node node) {
- _newline();
- _str.add(node);
- visitChildren(node);
- }
-
- visitChildren(Node node) {
- indent += 2;
- for (var child in node.nodes) visit(child);
- indent -= 2;
- }
-
- visitDocument(Document node) {
- indent += 1;
- for (var child in node.nodes) visit(child);
- indent -= 1;
- }
-
- visitElement(Element node) {
- _newline();
- _str.add(node);
- if (node.attributes.length > 0) {
- indent += 2;
- var keys = new List.from(node.attributes.getKeys());
- keys.sort((x, y) => x.compareTo(y));
- for (var key in keys) {
- var v = node.attributes[key];
- if (key is AttributeName) {
- AttributeName attr = key;
- key = "${attr.prefix} ${attr.name}";
- }
- _newline();
- _str.add('$key="$v"');
- }
- indent -= 2;
- }
- visitChildren(node);
- }
-}
« no previous file with comments | « tests/run.sh ('k') | tests/tokenizer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698