Skip to content
Merged
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
43 changes: 1 addition & 42 deletions tests_extractor.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private:
if (!config.attributes.empty)
return filterForUDAs(decl);
else
return hasDdocHeader(sourceCode, decl);
return decl.unittest_.comment !is null;
}

bool filterForUDAs(const Declaration decl)
Expand Down Expand Up @@ -302,47 +302,6 @@ to in the output directory.
}
}

bool hasDdocHeader(const(ubyte)[] sourceCode, const Declaration decl)
{
import std.algorithm.comparison : min;

bool hasComment;
size_t firstPos = size_t.max;

if (decl.unittest_ !is null)
{
firstPos = decl.unittest_.location;
hasComment = decl.unittest_.comment.length > 0;
}
else if (decl.functionDeclaration !is null)
{
// skip the return type
firstPos = sourceCode.skipPreviousWord(decl.functionDeclaration.name.index);
if (auto stClasses = decl.functionDeclaration.storageClasses)
firstPos = min(firstPos, stClasses[0].token.index);
hasComment = decl.functionDeclaration.comment.length > 0;
}
else if (decl.templateDeclaration !is null)
{
// skip the word `template`
firstPos = sourceCode.skipPreviousWord(decl.templateDeclaration.name.index);
hasComment = decl.templateDeclaration.comment.length > 0;
}

// libdparse will put any ddoc comment with at least one character in the comment field
if (hasComment)
return true;

firstPos = min(firstPos, getAttributesStartLocation(decl.attributes));

// scan the previous line for ddoc header -> skip to last real character
auto prevLine = sourceCode[0 .. firstPos].retro.find!(c => whitespace.countUntil(c) < 0);

// if there is no comment annotation, only three possible cases remain.
// one line ddoc: ///, multi-line comments: /** */ or /++ +/
return prevLine.filter!(c => !whitespace.canFind(c)).startsWith("///", "/+++/", "/***/") > 0;
}

/**
The location of unittest token is known, but there might be attributes preceding it.
*/
Expand Down