add newline after doc comments, add tests for doc comments

Bug: https://github.com/dart-lang/sdk/issues/55128
Change-Id: I6897e33ad291093d460e28a0b0f374d6504418e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356260
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Jake Macdonald 2024-03-07 16:58:00 +00:00 committed by Commit Queue
parent 0f1adddec3
commit f2e8464b98
3 changed files with 8 additions and 2 deletions

View file

@ -574,7 +574,7 @@ DeclarationCode _buildFunctionAugmentation(
assert(initializers == null || declaration is ConstructorDeclaration);
return new DeclarationCode.fromParts([
if (docComments != null) docComments,
if (docComments != null) ...[docComments, '\n'],
if (declaration is MethodDeclaration) ' ',
'augment ',
if (declaration is ConstructorDeclaration) ...[

View file

@ -676,6 +676,7 @@ class LibraryInfo {
expect(
result.libraryAugmentations.single.debugString().toString(),
equalsIgnoringWhitespace('''
// A comment!
augment String myFunction() {
print('isExternal: false');
print('isGetter: false');
@ -733,6 +734,7 @@ class LibraryInfo {
expect(
result.libraryAugmentations.single.debugString().toString(),
equalsIgnoringWhitespace('''
// A comment!
augment String get myVariable {
print('isExternal: false');
print('isGetter: true');
@ -754,6 +756,7 @@ class LibraryInfo {
expect(
result.libraryAugmentations.single.debugString().toString(),
equalsIgnoringWhitespace('''
// A comment!
augment void set myVariable(String value, ) {
print('isExternal: false');
print('isGetter: false');
@ -1020,6 +1023,7 @@ final fieldDefinitionMatchers = [
final methodDefinitionMatchers = [
equalsIgnoringWhitespace('''
// A comment!
augment (String, bool? hello, {String world}) myMethod() {
print('definingClass: MyClass');
print('isExternal: false');
@ -1050,6 +1054,7 @@ final methodDefinitionMatchers = [
final mixinMethodDefinitionMatchers = [
equalsIgnoringWhitespace('''
// A comment!
augment (String, bool? hello, {String world}) myMixinMethod() {
print('definingClass: MyMixin');
print('isExternal: false');

View file

@ -323,7 +323,8 @@ class SimpleMacro
@override
Future<void> buildDefinitionForFunction(
FunctionDeclaration function, FunctionDefinitionBuilder builder) async {
builder.augment(await _buildFunctionAugmentation(function, builder));
builder.augment(await _buildFunctionAugmentation(function, builder),
docComments: CommentCode.fromString('// A comment!'));
}
@override