-
Notifications
You must be signed in to change notification settings - Fork 134
#4134. Add new tests regarding whitespaces and interrupting lines #4135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sgrekhov
wants to merge
5
commits into
dart-lang:main
Choose a base branch
from
sgrekhov:sgrekhov-dartdoc-01
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
86c5190
#4134. Add/update tests regarding whitespaces and interrupting lines
sgrekhov 879f71e
Move tests to a separate directory
sgrekhov 6bc9749
Revert changes in documentation_comment_test.dart
sgrekhov 3abe33a
Update test/co19/line_based_doc_comments_test.dart
sgrekhov 840b567
Code optimization
sgrekhov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:analyzer/file_system/file_system.dart'; | ||
| import 'package:dartdoc/src/dartdoc_options.dart'; | ||
| import 'package:dartdoc/src/model/model.dart'; | ||
| import 'package:test/test.dart'; | ||
| import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
|
||
| import '../dartdoc_test_base.dart'; | ||
| import '../src/utils.dart' as utils; | ||
|
|
||
| @reflectiveTest | ||
| class Co19TestBase extends DartdocTestBase { | ||
| @override | ||
| String get libraryName => 'co19'; | ||
|
|
||
| late Folder projectRoot; | ||
| late PackageGraph packageGraph; | ||
| late ModelElement libraryModel; | ||
|
|
||
| void expectNoWarnings() { | ||
| expect(packageGraph.packageWarningCounter.countedWarnings, isEmpty); | ||
| expect(packageGraph.packageWarningCounter.hasWarnings, isFalse); | ||
| } | ||
|
|
||
| Future<void> writePackageWithCommentedLibraries( | ||
| List<(String, String)> filesAndComments, { | ||
| List<String> additionalArguments = const [], | ||
| }) async { | ||
| projectRoot = | ||
| utils.writePackage('co19', resourceProvider, packageConfigProvider); | ||
| projectRoot | ||
| .getChildAssumingFile('dartdoc_options.yaml') | ||
| .writeAsStringSync(''' | ||
| dartdoc: | ||
| warnings: | ||
| - missing-code-block-language | ||
| '''); | ||
|
|
||
| for (var (fileName, comment) in filesAndComments) { | ||
| projectRoot | ||
| .getChildAssumingFolder('lib') | ||
| .getChildAssumingFile(fileName) | ||
| .writeAsStringSync('$comment\n' | ||
| 'library;'); | ||
| } | ||
|
|
||
| var optionSet = DartdocOptionRoot.fromOptionGenerators( | ||
| 'dartdoc', [createDartdocOptions], packageMetaProvider); | ||
| optionSet.parseArguments([]); | ||
| packageGraph = await utils.bootBasicPackage( | ||
| projectRoot.path, packageMetaProvider, packageConfigProvider, | ||
| additionalArguments: additionalArguments); | ||
| libraryModel = packageGraph.defaultPackage.libraries.first; | ||
| } | ||
|
|
||
| Future<void> writePackageWithCommentedLibrary( | ||
| String comment, { | ||
| List<String> additionalArguments = const [], | ||
| }) => | ||
| writePackageWithCommentedLibraries([('a.dart', comment)], | ||
| additionalArguments: additionalArguments); | ||
|
|
||
| void expectDocComment(matcher) { | ||
| expect(libraryModel.documentation, matcher); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| /// @assertion A line-based doc comment is a comment that starts with `///`. One | ||
| /// or more consecutive lines that begin with `///` form a doc comment block. | ||
| /// | ||
| /// The block continues even if interrupted by single-line non-doc comments | ||
| /// (lines starting with `//`) or by blank lines. The interrupting lines are | ||
| /// ignored when extracting documentation text. | ||
| /// | ||
| /// For each line that begins with `///`, the parser removes the three slashes | ||
| /// and all leading whitespace to produce the documentation text. Exception: | ||
| /// inside fenced code blocks (` ``` `), whitespace after the leading `///` is | ||
| /// preserved to maintain code formatting. | ||
| /// @author sgrekhov22@gmail.com | ||
| library; | ||
|
|
||
| import 'package:test/test.dart'; | ||
| import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
|
||
| import 'co19_test_base.dart'; | ||
|
|
||
| void main() { | ||
| defineReflectiveSuite(() { | ||
| defineReflectiveTests(LineBasedDocCommentsTest); | ||
| }); | ||
| } | ||
|
|
||
| @reflectiveTest | ||
| class LineBasedDocCommentsTest extends Co19TestBase { | ||
| /// Check that the parser removes the three slashes and all leading | ||
| /// whitespaces | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: replace "whitespaces" with "whitespace" in general |
||
| void test_removesTripleSlashes() async { | ||
| await writePackageWithCommentedLibrary(''' | ||
| /// Text. | ||
| /// More text. | ||
| '''); | ||
| expectDocComment(equals(''' | ||
| Text. | ||
| More text.''')); | ||
| } | ||
|
|
||
| /// Check empty lines after three slashes are preserved | ||
| void test_leavesBlankLines() async { | ||
| await writePackageWithCommentedLibrary(''' | ||
| /// Text. | ||
| /// | ||
| /// More text. | ||
| '''); | ||
| expectDocComment(equals(''' | ||
| Text. | ||
|
|
||
| More text.''')); | ||
| } | ||
|
|
||
| /// Check that the parser removes the three slashes and all leading | ||
| /// whitespaces | ||
| void test_removesSpaceAfterTripleSlashes() async { | ||
| markTestSkipped('Skipping until issue ' | ||
| 'https://github.com/dart-lang/dartdoc/issues/4137 is resolved.'); | ||
| return; | ||
| await writePackageWithCommentedLibrary(''' | ||
| /// Text. | ||
| /// More text. | ||
| '''); | ||
| expectDocComment(equals(''' | ||
| 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. | ||
| '''); | ||
| expectDocComment(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. | ||
| '''); | ||
| expectDocComment(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!'); | ||
| /// } | ||
| /// ``` | ||
| '''); | ||
| expectDocComment(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!'); | ||
| /// } | ||
| /// ~~~ | ||
| '''); | ||
| expectDocComment(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 { | ||
| markTestSkipped('Skipping until issue ' | ||
| 'https://github.com/dart-lang/dartdoc/issues/4138 is resolved.'); | ||
| return; | ||
| await writePackageWithCommentedLibrary(''' | ||
| /// ` | ||
| /// void main() { | ||
| /// /// This line prints "Hello, world!" | ||
| /// print('Hello, world!'); | ||
| /// } | ||
| /// ` | ||
| '''); | ||
| expectDocComment(equals(''' | ||
| ` | ||
| void main() { | ||
| /// This line prints "Hello, world!" | ||
| print('Hello, world!'); | ||
| } | ||
| `''')); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.