Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 95 additions & 7 deletions test/documentation_comment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,15 @@ Text.
More text.'''));
}

/// Check that the parser removes the three slashes and all leading whitespaces
void test_removesSpaceAfterTripleSlashes() async {
await writePackageWithCommentedLibrary('''
/// Text.
/// More text.
''');
var doc = libraryModel.documentation;

// TODO(srawlins): Actually, the three spaces before 'More' is perhaps not
// the best fit. Should it only be two, to match the indent from the first
// line's "Text"?
expect(doc, equals('''
expect(libraryModel.documentation, equals('''
Text.
More text.'''));
More text.'''));
}

void test_leavesBlankLines() async {
Expand All @@ -111,6 +107,98 @@ Text.
More text.'''));
}

/// Check that interrupting blank lines and starting with `// ` are ignored.
void test_interruptingLinesIgnored() async {
await writePackageWithCommentedLibrary('''
/// Text.
//
/// More text.
// Some text
/// And more text.

/// And more.
''');
expect(libraryModel.documentation, equals('''
Text.
More text.
And more text.
And more.'''));
}

/// Check that the doc comment starts after `///` even there is no trailing
/// whitespace.
void test_noTrailingWhitespace() async {
await writePackageWithCommentedLibrary('''
//// Text.
/////More text.
///And more.
''');
expect(libraryModel.documentation, equals('''
/ Text.
//More text.
And more.'''));
}

/// Check that inside fenced code blocks (```), whitespaces after the leading
/// `///` are preserved
void test_whitespacesInBacktickCodeBlocks() async {
await writePackageWithCommentedLibrary('''
/// ```
/// void main() {
/// /// This line prints "Hello, world!"
/// print('Hello, world!');
/// }
/// ```
''');
expect(libraryModel.documentation, equals('''
```
void main() {
/// This line prints "Hello, world!"
print('Hello, world!');
}
```'''));
}

/// Check that inside fenced code blocks (~~~), whitespaces after the leading
/// `///` are preserved
void test_whitespacesInTildesCodeBlocks() async {
await writePackageWithCommentedLibrary('''
/// ~~~
/// void main() {
/// /// This line prints "Hello, world!"
/// print('Hello, world!');
/// }
/// ~~~
''');
expect(libraryModel.documentation, equals('''
~~~
void main() {
/// This line prints "Hello, world!"
print('Hello, world!');
}
~~~'''));
}

/// Check that inside fenced code span (`), whitespaces after the leading
/// `///` are removed.
void test_whitespacesInCodeSpan() async {
await writePackageWithCommentedLibrary('''
/// `
/// void main() {
/// /// This line prints "Hello, world!"
/// print('Hello, world!');
/// }
/// `
''');
expect(libraryModel.documentation, equals('''
`
void main() {
/// This line prints "Hello, world!"
print('Hello, world!');
}
`'''));
}

void test_processesAnimationDirective() async {
await writePackageWithCommentedLibrary('''
/// Text.
Expand Down
Loading