| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, 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 import 'package:expect/expect.dart'; | |
| 6 import "package:async_helper/async_helper.dart"; | |
| 7 import 'dart:async'; | |
| 8 import 'mirror_system_helper.dart'; | |
| 9 | |
| 10 Future validateDeclarationComment(String code, | |
| 11 String text, | |
| 12 String trimmedText, | |
| 13 bool isDocComment, | |
| 14 List<Symbol> declarationNames) { | |
| 15 return createMirrorSystem(code).then((mirrors) { | |
| 16 LibraryMirror library = mirrors.libraries[SOURCE_URI]; | |
| 17 Expect.isNotNull(library); | |
| 18 for (Symbol declarationName in declarationNames) { | |
| 19 DeclarationMirror declaration = library.declarations[declarationName]; | |
| 20 Expect.isNotNull(declaration); | |
| 21 List<InstanceMirror> metadata = declaration.metadata; | |
| 22 Expect.isNotNull(metadata); | |
| 23 Expect.equals(1, metadata.length); | |
| 24 Expect.isTrue(metadata[0] is CommentInstanceMirror); | |
| 25 CommentInstanceMirror commentMetadata = metadata[0]; | |
| 26 Expect.equals(text, commentMetadata.text); | |
| 27 Expect.equals(trimmedText, commentMetadata.trimmedText); | |
| 28 Expect.equals(isDocComment, commentMetadata.isDocComment); | |
| 29 } | |
| 30 }); | |
| 31 } | |
| 32 | |
| 33 Future testDeclarationComment(String declaration, | |
| 34 List<Symbol> declarationNames) { | |
| 35 return Future.forEach([ | |
| 36 () { | |
| 37 String text = 'Single line comment'; | |
| 38 String comment = '// $text'; | |
| 39 String code = '$comment\n$declaration'; | |
| 40 return validateDeclarationComment( | |
| 41 code, comment, text, false, declarationNames); | |
| 42 }, | |
| 43 () { | |
| 44 String text = 'Single line comment'; | |
| 45 String comment = '/// $text'; | |
| 46 String code = '$comment\n$declaration'; | |
| 47 return validateDeclarationComment( | |
| 48 code, comment, text, true, declarationNames); | |
| 49 }, | |
| 50 () { | |
| 51 String text = 'Multiline comment'; | |
| 52 String comment = '/* $text*/'; | |
| 53 String code = '$comment$declaration'; | |
| 54 return validateDeclarationComment( | |
| 55 code, comment, text, false, declarationNames); | |
| 56 }, | |
| 57 () { | |
| 58 String text = 'Multiline comment'; | |
| 59 String comment = '/** $text*/'; | |
| 60 String code = '$comment$declaration'; | |
| 61 return validateDeclarationComment( | |
| 62 code, comment, text, true, declarationNames); | |
| 63 }, | |
| 64 ], (f) => f()); | |
| 65 } | |
| 66 | |
| 67 void main() { | |
| 68 asyncTest(() => Future.forEach([ | |
| 69 () => testDeclarationComment('var field;', [#field]), | |
| 70 () => testDeclarationComment('int field;', [#field]), | |
| 71 () => testDeclarationComment('int field = 0;', [#field]), | |
| 72 () => testDeclarationComment('int field1, field2;', [#field1, #field2]), | |
| 73 () => testDeclarationComment('final field = 0;', [#field]), | |
| 74 () => testDeclarationComment('final int field = 0;', [#field]), | |
| 75 () => testDeclarationComment('final field1 = 0, field2 = 0;', | |
| 76 [#field1, #field2]), | |
| 77 () => testDeclarationComment('final int field1 = 0, field2 = 0;', | |
| 78 [#field1, #field2]), | |
| 79 () => testDeclarationComment('const field = 0;', [#field]), | |
| 80 () => testDeclarationComment('const int field = 0;', [#field]), | |
| 81 () => testDeclarationComment('const field1 = 0, field2 = 0;', | |
| 82 [#field1, #field2]), | |
| 83 () => testDeclarationComment('const int field1 = 0, field2 = 0;', | |
| 84 [#field1, #field2]), | |
| 85 ], (f) => f())); | |
| 86 } | |
| OLD | NEW |