Permalink
Browse files

Add more tests for doc comment fix and fix an edge case. (#741)

A line that didn't have a leading "*" but did have a "*" elsewhere in
the line would have everything before the "*" trimmed.
  • Loading branch information...
munificent committed Sep 17, 2018
1 parent 6622671 commit 011ac717bb260aa0af2798cb255c82008e5f1040
Showing with 54 additions and 8 deletions.
  1. +8 −8 lib/src/chunk_builder.dart
  2. +46 −0 test/fixes/doc_comments.stmt
View
@@ -22,8 +22,8 @@ final _trailingIdentifierChar = new RegExp(r"[a-zA-Z0-9_]$");
/// "*/" or "**/".
final _javaDocComment = new RegExp(r"^/\*\*([^*/][\s\S]*?)\*?\*/$");
/// Matches an intermediate "*" line in the middle of a JavaDoc-style comment.
var _javaDocLine = new RegExp(r"\s*\*(.*)");
/// Matches the leading "*" in a line in the middle of a JavaDoc-style comment.
var _javaDocLine = new RegExp(r"^\s*\*(.*)");
/// Takes the incremental serialized output of [SourceVisitor]--the source text
/// along with any comments and preserved whitespace--and produces a coherent
@@ -357,13 +357,9 @@ class ChunkBuilder {
return;
}
// Trim the first and last lines if empty.
var lines = match.group(1).split("\n").toList();
if (lines.first.trim().isEmpty) lines.removeAt(0);
if (lines.isNotEmpty && lines.last.trim().isEmpty) lines.removeLast();
// Remove a leading "*" from the middle lines.
for (var i = 0; i < lines.length; i++) {
var lines = match.group(1).split("\n").toList();
for (var i = 1; i < lines.length - 1; i++) {
var line = lines[i];
var match = _javaDocLine.firstMatch(line);
if (match != null) {
@@ -376,6 +372,10 @@ class ChunkBuilder {
lines[i] = line;
}
// Trim the first and last lines if empty.
if (lines.first.trim().isEmpty) lines.removeAt(0);
if (lines.isNotEmpty && lines.last.trim().isEmpty) lines.removeLast();
// Don't completely eliminate an empty block comment.
if (lines.isEmpty) lines.add("");
@@ -110,4 +110,50 @@ m() {}
/*******
* STUFF
*******/
m() {}
>>> nested comment
/**
* Floo the grumshack.
*
* Example:
* ```dart
* /** Doc comment */
* var grumshack = getGrumshack();
* /* Do the floo */
* grumshack.floo();
* ```
*/
m() {}
<<<
/// Floo the grumshack.
///
/// Example:
/// ```dart
/// /** Doc comment */
/// var grumshack = getGrumshack();
/// /* Do the floo */
/// grumshack.floo();
/// ```
m() {}
>>>
/** Does a [foo](http://example.org/*example*/doc). **/
m() {}
<<<
/// Does a [foo](http://example.org/*example*/doc).
m() {}
>>>
/** Does a [foo](http://example.org/*example*/doc). */
m() {}
<<<
/// Does a [foo](http://example.org/*example*/doc).
m() {}
>>> non-leading "*"
/**
* Thing.
Another * thing.
*/
m() {}
<<<
/// Thing.
/// Another * thing.
m() {}

0 comments on commit 011ac71

Please sign in to comment.