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

Side by Side Diff: pkg/docgen/test/generate_json_test.dart

Issue 203753005: pkg/docgen: test fixes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/docgen/test/multi_library_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import 'dart:convert'; 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library docgen.generate_json_test;
6
2 import 'dart:io'; 7 import 'dart:io';
3 8
4 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
5 import 'package:scheduled_test/descriptor.dart' as d; 10 import 'package:scheduled_test/descriptor.dart' as d;
6 import 'package:scheduled_test/scheduled_test.dart'; 11 import 'package:scheduled_test/scheduled_test.dart';
7 import 'package:unittest/matcher.dart'; 12 import 'package:unittest/matcher.dart';
8 13
9 import 'util.dart'; 14 import 'util.dart';
10 import '../lib/docgen.dart' as dg; 15 import '../lib/docgen.dart' as dg;
11 16
12 void main() { 17 void main() {
13 18
14 setUp(() { 19 setUp(() {
15 var tempDir; 20 scheduleTempDir();
16 schedule(() { 21 });
17 return Directory.systemTemp
18 .createTemp('docgen_test-')
19 .then((dir) {
20 tempDir = dir;
21 d.defaultRoot = tempDir.path;
22 });
23 });
24
25 currentSchedule.onComplete.schedule(() {
26 d.defaultRoot = null;
27 return tempDir.delete(recursive: true);
28 });
29 });
30 22
31 test('json output', () { 23 test('json output', () {
32 schedule(() { 24 schedule(() {
33 var codeDir = getMultiLibraryCodePath(); 25 var codeDir = getMultiLibraryCodePath();
34 expect(FileSystemEntity.isDirectorySync(codeDir), isTrue); 26 expect(FileSystemEntity.isDirectorySync(codeDir), isTrue);
35 return dg.docgen([codeDir], out: p.join(d.defaultRoot, 'docs')); 27 return dg.docgen([codeDir], out: p.join(d.defaultRoot, 'docs'));
36 }); 28 });
37 29
38 d.dir('docs', [ 30 d.dir('docs', [
39 d.matcherFile('index.json', _isJsonMap), 31 d.matcherFile('index.json', isJsonMap),
40 d.matcherFile('index.txt', _hasSortedLines), 32 d.matcherFile('index.txt', hasSortedLines),
41 d.matcherFile('library_list.json', _isJsonMap), 33 d.matcherFile('library_list.json', isJsonMap),
42 d.matcherFile('test_lib-bar.C.json', _isJsonMap), 34 d.matcherFile('test_lib-bar.C.json', isJsonMap),
43 d.matcherFile('test_lib-bar.json', _isJsonMap), 35 d.matcherFile('test_lib-bar.json', isJsonMap),
44 d.matcherFile('test_lib-foo.B.json', _isJsonMap), 36 d.matcherFile('test_lib-foo.B.json', isJsonMap),
45 d.matcherFile('test_lib-foo.json', _isJsonMap), 37 d.matcherFile('test_lib-foo.json', isJsonMap),
46 d.matcherFile('test_lib.A.json', _isJsonMap), 38 d.matcherFile('test_lib.A.json', isJsonMap),
47 d.matcherFile('test_lib.B.json', _isJsonMap), 39 d.matcherFile('test_lib.B.json', isJsonMap),
48 d.matcherFile('test_lib.C.json', _isJsonMap), 40 d.matcherFile('test_lib.C.json', isJsonMap),
49 d.matcherFile('test_lib.json', _isJsonMap), 41 d.matcherFile('test_lib.json', isJsonMap),
50 ]).validate();
51
52 });
53
54 test('typedef gen', () {
55 schedule(() {
56 var codeDir = getMultiLibraryCodePath();
57 expect(FileSystemEntity.isDirectorySync(codeDir), isTrue);
58 return dg.docgen([codeDir], out: p.join(d.defaultRoot, 'docs'));
59 });
60
61 schedule(() {
62 var path = p.join(d.defaultRoot, 'docs', 'test_lib-bar.json');
63 var dartCoreJson = new File(path).readAsStringSync();
64
65 var testLibBar = JSON.decode(dartCoreJson) as Map<String, dynamic>;
66
67 //
68 // Validate function doc references
69 //
70 var generateFoo = testLibBar['functions']['methods']['generateFoo']
71 as Map<String, dynamic>;
72
73 expect(generateFoo['comment'], '<p><a>test_lib-bar.generateFoo.input</a> '
74 'is of type <a>test_lib-bar.C</a> returns an <a>test_lib.A</a>.</p>');
75
76 var classes = testLibBar['classes'] as Map<String, dynamic>;
77
78 expect(classes, hasLength(3));
79
80 expect(classes['class'], isList);
81 expect(classes['error'], isList);
82
83 var typeDefs = classes['typedef'] as Map<String, dynamic>;
84 var comparator = typeDefs['AnATransformer'] as Map<String, dynamic>;
85
86 var expectedPreview = '<p>Processes a [C] instance for testing.</p>';
87
88 expect(comparator['preview'], expectedPreview);
89
90 var expectedComment = expectedPreview + '\n'
91 '<p>To eliminate import warnings for [A] and to test typedefs.</p>';
92
93 expect(comparator['comment'], expectedComment);
94 });
95 });
96
97 test('exclude non-lib code from package docs', () {
98 schedule(() {
99 var thisScript = Platform.script;
100 var thisPath = p.fromUri(thisScript);
101 expect(p.basename(thisPath), 'generate_json_test.dart');
102 expect(p.dirname(thisPath), endsWith('test'));
103
104
105 var codeDir = p.normalize(p.join(thisPath, '..', '..'));
106 print(codeDir);
107 expect(FileSystemEntity.isDirectorySync(codeDir), isTrue);
108 return dg.docgen(['$codeDir/'], out: p.join(d.defaultRoot, 'docs'));
109 });
110
111 d.dir('docs', [
112 d.dir('docgen', [
113 d.matcherFile('docgen.json', _isJsonMap)
114 ]),
115 d.matcherFile('index.json', _isJsonMap),
116 d.matcherFile('index.txt', _hasSortedLines),
117 d.matcherFile('library_list.json', _isJsonMap),
118 d.nothing('test_lib.json'),
119 d.nothing('test_lib-bar.json'),
120 d.nothing('test_lib-foo.json')
121 ]).validate(); 42 ]).validate();
122 43
123 }); 44 });
124 } 45 }
125
126 final Matcher _hasSortedLines = predicate((String input) {
127 var lines = new LineSplitter().convert(input);
128
129 var sortedLines = new List.from(lines)..sort();
130
131 var orderedMatcher = orderedEquals(sortedLines);
132 return orderedMatcher.matches(lines, {});
133 }, 'String has sorted lines');
134
135 final Matcher _isJsonMap = predicate((input) {
136 try {
137 return JSON.decode(input) is Map;
138 } catch (e) {
139 return false;
140 }
141 }, 'Output is JSON encoded Map');
OLDNEW
« no previous file with comments | « no previous file | pkg/docgen/test/multi_library_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698