Skip to content

Commit

Permalink
fix & test formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Jun 20, 2022
1 parent aa2eeca commit 37ed9fa
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/dparse/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -1740,10 +1740,12 @@ class Formatter(Sink)

with(ifCondition)
{
bool isAuto = identifier != tok!"" && !type;
bool isAssign = isAuto || type || typeCtors.length;
bool isAuto = identifier != tok!"" && !type && !scope_;
bool isScope = identifier != tok!"" && scope_;
bool isAssign = isAuto || isScope || type || typeCtors.length;

if (isAuto) put("auto ");
if (isScope) put("scope ");
foreach(tct; typeCtors)
{
put(str(tct));
Expand Down Expand Up @@ -3740,11 +3742,6 @@ class Formatter(Sink)
{
debug(verbose) writeln("WhileStatement");

/**
Expression expression;
DeclarationOrStatement declarationOrStatement;
**/

newThing(What.other);
put("while (");
format(stmt.condition);
Expand Down Expand Up @@ -4269,4 +4266,29 @@ do
foo(a, throw b, c);
return throw new Exception("", "");
}});

testFormatNode!(IfCondition)(q{void foo()
{
if (scope x = readln())
{
}
}}, `scope x = readln()`);
testFormatNode!(IfCondition)(q{void foo()
{
if (auto x = readln())
{
}
}}, `auto x = readln()`);
testFormatNode!(IfCondition)(q{void foo()
{
while (const inout string x = readln())
{
}
}}, `const inout string x = readln()`);
testFormatNode!(IfCondition)(q{void foo()
{
if (a == b && c == d)
{
}
}}, `a == b && c == d`);
}

0 comments on commit 37ed9fa

Please sign in to comment.