Skip to content
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

ddoc/source/assert_writeln_magic: Add a new "// no-writeln" syntax #3801

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions ddoc/source/assert_writeln_magic.d
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class TestVisitor(Out) : ASTVisitor
{
import std.uni : isWhite;
import std.format : format;
import std.string : stripRight;

if (fromAssert && !fromStaticAssert &&
lastEqualExpression !is null && lastAssert !is null)
Expand All @@ -129,6 +130,13 @@ class TestVisitor(Out) : ASTVisitor
// libdparse starts the line count with 1
auto lineNr = lastAssert.line - 1;

static immutable negation = "// no-writeln";

if (fl[lineNr].endsWith(negation))
{
fl[lineNr] = fl[lineNr][0 .. $ - negation.length].stripRight;
}
else
// only replace single-line expressions (for now)
if (fl[lineNr].endsWith(";"))
{
Expand Down Expand Up @@ -306,6 +314,7 @@ unittest
unittest
{
assert(1 == 2);
assert(1 == 2); // no-writeln
assert(foo() == "bar");
assert(foo() == bar);
assert(arr == [0, 1, 2]);
Expand All @@ -315,6 +324,7 @@ assert(r.back == 1);
auto res = runTest(testCode);
assert(res.lines[3 .. $ - 2] == [
"writeln(1); // 2",
"assert(1 == 2);",
"writeln(foo()); // \"bar\"",
"writeln(foo()); // bar",
"writeln(arr); // [0, 1, 2]",
Expand Down