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

Side by Side 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 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 import '../../../pkg/unittest/lib/unittest.dart';
2 import '../lib/HtmlToJson.dart' as htmlToJson;
3 import '../lib/JsonToHtml.dart' as jsonToHtml;
4 import 'dart:json';
5 import 'dart:io';
6
7 void main() {
8 var scriptPath = new Path(new Options().script).directoryPath.toString();
9
10 test('HTML Doc to JSON', () {
11 var htmlPath = new Path('$scriptPath/test_data/htmlToJson');
12 var jsonPath = new Path('$scriptPath/test_output/htmlToJsonTest.json');
13
14 var convertFuture = htmlToJson.convert(htmlPath, jsonPath);
15
16 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.
17 var output = new File.fromPath(jsonPath);
18
19 var goldenFile = new File(
20 '$scriptPath/test_data/htmlToJson/htmlToJsonTestGoldenOutput.json');
21
22 expect(anyErrors, false, reason:'The conversion completed with errors.');
23 expect(output.readAsStringSync(), goldenFile.readAsStringSync());
24 });
25 });
26
27 test('JSON to HTML Doc', () {
28 var preHtmlPath = new Path('$scriptPath/test_data/jsonToHtml');
29 var goldenHtmlPath = new Path('$scriptPath/test_data/htmlToJson');
30 var htmlPath = new Path('$scriptPath/test_output');
31 var jsonPath = new Path('$scriptPath/test_output/htmlToJsonTest.json');
32
33 var copyFuture = _copyFiles(preHtmlPath, htmlPath);
34
35 copyFuture.then((_) {
36 var convertFuture = jsonToHtml.convert(htmlPath, jsonPath);
37
38 convertFuture.then((anyErrors) {
39 expect(anyErrors, false,
40 reason:'The conversion completed with errors.');
41
42 _compareFilesInDirectories(goldenHtmlPath, htmlPath);
43
44 });
45 });
46 });
47 }
48
49 void _compareFilesInDirectories(Path path1, Path path2) {
50 final dir1 = new Directory.fromPath(path1);
51 final dir2 = new Directory.fromPath(path2);
52 final lister1 = dir1.list(recursive: false);
53 final lister2 = dir2.list(recursive: false);
54
55 // True once one of the listers is finished.
56 var oneFinished = false;
57
58 var list1 = <String, File>{};
59
60 lister1.onFile = (String path) {
61 if (path.endsWith('.dart')) {
62 list1.putIfAbsent(new Path(path).filename, () => new File(path));
63 }
64 };
65
66 lister1.onDone = (_) {
67 lister2.onFile = (String path) {
68 if (path.endsWith('.dart')) {
69 expect(list1[new Path(path).filename].readAsStringSync(),
70 new File(path).readAsStringSync());
71 }
72 };
73 };
74 }
75
76 Future _copyFiles(Path fromDir, Path toDir) {
77 // First copy the files into a new place to keep the old files.
78 final completer = new Completer();
79 final htmlDir = new Directory.fromPath(fromDir);
80 final lister = htmlDir.list(recursive: false);
81
82 lister.onFile = (String path) {
83 final name = new Path.fromNative(path).filename;
84
85 // Ignore private classes.
86 if (name.startsWith('_')) return;
87
88 // Ignore non-dart files.
89 if (!name.endsWith('.dart')) return;
90
91 File file = new File(path);
92 File newFile = new File.fromPath(toDir.append(name));
93
94 var outputStream = newFile.openOutputStream();
95 outputStream.writeString(file.readAsStringSync());
96 };
97
98 lister.onDone = (_) {
99 completer.complete(null);
100 };
101 return completer.future;
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698