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