From 355e5cd71198d4b342514e3b4b51d7d6dc5b8a8c Mon Sep 17 00:00:00 2001 From: MoonlightSentinel Date: Sun, 3 May 2020 21:28:57 +0200 Subject: [PATCH] Remove unused code from test_extractor.d `hasDdocHeader` was only called if `decl.unittest_` wasn't null and hence only executed the first if-branch. The remainder of that method is obsolete because dparse sets `comment` even for empty ddoc comments (see dlang-community/libdparse#401). Relying on dparse also removes some false positives/negatives, e.g. ``` /// // Some comment unittest {} // Ignored //////////////////////////////////////////////////////////////////////////////// // Unit Tests //////////////////////////////////////////////////////////////////////////////// unittest {} // Extracted ``` --- tests_extractor.d | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/tests_extractor.d b/tests_extractor.d index 90ea75c947..82d16d6572 100755 --- a/tests_extractor.d +++ b/tests_extractor.d @@ -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) @@ -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. */