OLD | NEW |
| (Empty) |
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 async_await_test; | |
6 | |
7 import 'dart:io'; | |
8 | |
9 import 'package:path/path.dart' as path; | |
10 import 'package:unittest/unittest.dart'; | |
11 | |
12 import '../lib/src/exports/mirrors_util.dart' as dart2js_util; | |
13 import '../lib/src/models/annotation.dart'; | |
14 import '../lib/docgen.dart'; | |
15 | |
16 const Map<String, String> SOURCES = const <String, String>{ | |
17 'main.dart': ''' | |
18 import 'lib.dart' as lib; | |
19 | |
20 @lib.Annotation("foo", 42) | |
21 main() { | |
22 } | |
23 ''', | |
24 'lib.dart': ''' | |
25 class Annotation { | |
26 final String arg1; | |
27 final int arg2; | |
28 const Annotation(this.arg1, this.arg2); | |
29 } | |
30 '''}; | |
31 | |
32 main() { | |
33 group('Generate docs for', () { | |
34 test('files with annotations', () { | |
35 var temporaryDir = Directory.systemTemp.createTempSync('metadata_'); | |
36 var uris = <Uri>[]; | |
37 SOURCES.forEach((name, code) { | |
38 var fileName = path.join(temporaryDir.path, name); | |
39 var file = new File(fileName); | |
40 file.writeAsStringSync(code); | |
41 uris.add(new Uri.file(fileName)); | |
42 }); | |
43 | |
44 return getMirrorSystem(uris, false).then((mirrorSystem) { | |
45 var library = new Library(mirrorSystem.libraries[uris[0]]); | |
46 expect(library is Library, isTrue); | |
47 | |
48 var main = library.functions['main']; | |
49 expect(main is Method, isTrue); | |
50 | |
51 var annotations = main.annotations; | |
52 expect(annotations.length, equals(1)); | |
53 | |
54 var annotation = annotations[0]; | |
55 expect(annotation is Annotation, isTrue); | |
56 | |
57 var map = annotation.toMap(); | |
58 expect(map['name'], equals('lib-dart.Annotation.Annotation-')); | |
59 expect(map['parameters'].length, equals(2)); | |
60 expect(map['parameters'][0], equals('"foo"')); | |
61 expect(map['parameters'][1], equals('42')); | |
62 }).whenComplete(() => temporaryDir.deleteSync(recursive: true)); | |
63 }); | |
64 }); | |
65 } | |
OLD | NEW |