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

Unified Diff: tools/html-json-doc/test/HtmlJsonDoc_test.dart

Issue 11280133: Both halves of the HTMLDoc to JSON doc converter! (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed bin. 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 side-by-side diff with in-line comments
Download patch
Index: tools/html-json-doc/test/HtmlJsonDoc_test.dart
diff --git a/tools/html-json-doc/test/HtmlJsonDoc_test.dart b/tools/html-json-doc/test/HtmlJsonDoc_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d8fb7d49937903b677b60d15c74d02ccfcb29201
--- /dev/null
+++ b/tools/html-json-doc/test/HtmlJsonDoc_test.dart
@@ -0,0 +1,102 @@
+import '../../../pkg/unittest/lib/unittest.dart';
+import '../lib/HtmlToJson.dart' as htmlToJson;
+import '../lib/JsonToHtml.dart' as jsonToHtml;
+import 'dart:json';
+import 'dart:io';
+
+void main() {
+ var scriptPath = new Path(new Options().script).directoryPath.toString();
+
+ test('HTML Doc to JSON', () {
+ var htmlPath = new Path('$scriptPath/test_data/htmlToJson');
+ var jsonPath = new Path('$scriptPath/test_output/htmlToJsonTest.json');
+
+ var convertFuture = htmlToJson.convert(htmlPath, jsonPath);
+
+ convertFuture.then((anyErrors) {
Bob Nystrom 2012/11/26 22:00:19 Async tests are a little different. You'll need to
Andrei Mouravski 2012/11/27 03:11:45 Done.
+ var output = new File.fromPath(jsonPath);
+
+ var goldenFile = new File(
+ '$scriptPath/test_data/htmlToJson/htmlToJsonTestGoldenOutput.json');
+
+ expect(anyErrors, false, reason:'The conversion completed with errors.');
+ expect(output.readAsStringSync(), goldenFile.readAsStringSync());
+ });
+ });
+
+ test('JSON to HTML Doc', () {
+ var preHtmlPath = new Path('$scriptPath/test_data/jsonToHtml');
+ var goldenHtmlPath = new Path('$scriptPath/test_data/htmlToJson');
+ var htmlPath = new Path('$scriptPath/test_output');
+ var jsonPath = new Path('$scriptPath/test_output/htmlToJsonTest.json');
+
+ var copyFuture = _copyFiles(preHtmlPath, htmlPath);
+
+ copyFuture.then((_) {
+ var convertFuture = jsonToHtml.convert(htmlPath, jsonPath);
+
+ convertFuture.then((anyErrors) {
+ expect(anyErrors, false,
+ reason:'The conversion completed with errors.');
+
+ _compareFilesInDirectories(goldenHtmlPath, htmlPath);
+
+ });
+ });
+ });
+}
+
+void _compareFilesInDirectories(Path path1, Path path2) {
+ final dir1 = new Directory.fromPath(path1);
+ final dir2 = new Directory.fromPath(path2);
+ final lister1 = dir1.list(recursive: false);
+ final lister2 = dir2.list(recursive: false);
+
+ // True once one of the listers is finished.
+ var oneFinished = false;
+
+ var list1 = <String, File>{};
+
+ lister1.onFile = (String path) {
+ if (path.endsWith('.dart')) {
+ list1.putIfAbsent(new Path(path).filename, () => new File(path));
+ }
+ };
+
+ lister1.onDone = (_) {
+ lister2.onFile = (String path) {
+ if (path.endsWith('.dart')) {
+ expect(list1[new Path(path).filename].readAsStringSync(),
+ new File(path).readAsStringSync());
+ }
+ };
+ };
+}
+
+Future _copyFiles(Path fromDir, Path toDir) {
+ // First copy the files into a new place to keep the old files.
+ final completer = new Completer();
+ final htmlDir = new Directory.fromPath(fromDir);
+ final lister = htmlDir.list(recursive: false);
+
+ lister.onFile = (String path) {
+ final name = new Path.fromNative(path).filename;
+
+ // Ignore private classes.
+ if (name.startsWith('_')) return;
+
+ // Ignore non-dart files.
+ if (!name.endsWith('.dart')) return;
+
+ File file = new File(path);
+ File newFile = new File.fromPath(toDir.append(name));
+
+ var outputStream = newFile.openOutputStream();
+ outputStream.writeString(file.readAsStringSync());
+ };
+
+ lister.onDone = (_) {
+ completer.complete(null);
+ };
+ return completer.future;
+}

Powered by Google App Engine
This is Rietveld 408576698