OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library docgen.test.typedef; | 5 library docgen.test.typedef; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 10 matching lines...) Expand all Loading... |
21 }); | 21 }); |
22 | 22 |
23 test('typedef gen', () { | 23 test('typedef gen', () { |
24 schedule(() { | 24 schedule(() { |
25 var codeDir = getMultiLibraryCodePath(); | 25 var codeDir = getMultiLibraryCodePath(); |
26 expect(FileSystemEntity.isDirectorySync(codeDir), isTrue); | 26 expect(FileSystemEntity.isDirectorySync(codeDir), isTrue); |
27 return dg.docgen([codeDir], out: p.join(d.defaultRoot, 'docs')); | 27 return dg.docgen([codeDir], out: p.join(d.defaultRoot, 'docs')); |
28 }); | 28 }); |
29 | 29 |
30 schedule(() { | 30 schedule(() { |
31 var path = p.join(d.defaultRoot, 'docs', 'test_lib-bar.json'); | 31 var path = p.join(d.defaultRoot, 'docs', 'root_lib.json'); |
32 var dartCoreJson = new File(path).readAsStringSync(); | 32 var dartCoreJson = new File(path).readAsStringSync(); |
33 | 33 |
34 var testLibBar = JSON.decode(dartCoreJson) as Map<String, dynamic>; | 34 var testLibBar = JSON.decode(dartCoreJson) as Map<String, dynamic>; |
35 | 35 |
36 // | 36 // |
37 // Validate function doc references | 37 // Validate function doc references |
38 // | 38 // |
39 var generateFoo = testLibBar['functions']['methods']['generateFoo'] | 39 var testMethod = testLibBar['functions']['methods']['testMethod'] |
40 as Map<String, dynamic>; | 40 as Map<String, dynamic>; |
41 | 41 |
42 expect(generateFoo['comment'], '<p><a>test_lib-bar.generateFoo.input</a> ' | 42 expect(testMethod['comment'], _TEST_METHOD_COMMENT); |
43 'is of type <a>test_lib-bar.C</a> returns an <a>test_lib.A</a>.</p>'); | |
44 | 43 |
45 var classes = testLibBar['classes'] as Map<String, dynamic>; | 44 var classes = testLibBar['classes'] as Map<String, dynamic>; |
46 | 45 |
47 expect(classes, hasLength(3)); | 46 expect(classes, hasLength(3)); |
48 | 47 |
49 expect(classes['class'], isList); | 48 expect(classes['class'], isList); |
50 expect(classes['error'], isList); | 49 expect(classes['error'], isList); |
51 | 50 |
52 var typeDefs = classes['typedef'] as Map<String, dynamic>; | 51 var typeDefs = classes['typedef'] as Map<String, dynamic>; |
53 var comparator = typeDefs['AnATransformer'] as Map<String, dynamic>; | 52 var comparator = typeDefs['testTypedef'] as Map<String, dynamic>; |
54 | 53 |
55 var expectedPreview = | 54 expect(comparator['preview'], _TEST_TYPEDEF_PREVIEW); |
56 '<p>Processes a <a>test_lib-bar.C</a> instance for testing.</p>'; | |
57 | 55 |
58 expect(comparator['preview'], expectedPreview); | 56 expect(comparator['comment'], _TEST_TYPEDEF_COMMENT); |
59 | |
60 var expectedComment = expectedPreview + '\n' | |
61 '<p>To eliminate import warnings for <a>test_lib.A</a> and to test ' | |
62 'typedefs.</p>'; | |
63 | |
64 expect(comparator['comment'], expectedComment); | |
65 }); | 57 }); |
66 }); | 58 }); |
67 } | 59 } |
| 60 |
| 61 // TOOD: [List<A>] is not formatted correctly - issue 16771 |
| 62 const _TEST_METHOD_COMMENT = '<p>Processes an ' |
| 63 '<a>root_lib.testMethod.input</a> of type <a>root_lib.C</a> ' |
| 64 'instance for testing.</p>\n<p>To eliminate import warnings for ' |
| 65 '<a>root_lib.A</a> and to test typedefs.</p>\n<p>It\'s important that the' |
| 66 ' <a>dart-core</a><A> for param <a>root_lib.testMethod.listOfA</a> ' |
| 67 'is not empty.</p>'; |
| 68 |
| 69 // TODO: [input] is not turned into a param refenece |
| 70 const _TEST_TYPEDEF_PREVIEW = '<p>Processes an input of type ' |
| 71 '<a>root_lib.C</a> instance for testing.</p>'; |
| 72 |
| 73 // TOOD: [List<A>] is not formatted correctly - issue 16771 |
| 74 // TODO: [listOfA] is not turned into a param reference |
| 75 final _TEST_TYPEDEF_COMMENT = _TEST_TYPEDEF_PREVIEW + '\n<p>To eliminate import' |
| 76 ' warnings for <a>root_lib.A</a> and to test typedefs.</p>\n<p>It\'s ' |
| 77 'important that the <a>dart-core</a><A> for param listOfA is not ' |
| 78 'empty.</p>'; |
| 79 |
OLD | NEW |