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
105 changes: 100 additions & 5 deletions src/dparse/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ class Formatter(Sink)
void format(const InContractExpression expression)
{
debug(verbose) writeln("InContractExpression");

newlineIndent();
put("in (");
format(expression.assertArguments);
put(")");
Expand All @@ -1904,7 +1904,6 @@ class Formatter(Sink)
{
if (inContractExpression) format(inContractExpression);
if (outContractExpression) format(outContractExpression);
newline();
}
}

Expand All @@ -1922,6 +1921,7 @@ class Formatter(Sink)
void format(const InStatement inStatement)
{
debug(verbose) writeln("InStatement");
newlineIndent();
put("in");
format(inStatement.blockStatement);
}
Expand Down Expand Up @@ -2346,7 +2346,7 @@ class Formatter(Sink)
void format(const OutContractExpression expression)
{
debug(verbose) writeln("OutContractExpression");

newlineIndent();
put("out (");
if (expression.parameter != tok!"")
format(expression.parameter);
Expand All @@ -2363,7 +2363,7 @@ class Formatter(Sink)
Token parameter;
BlockStatement blockStatement;
**/

newlineIndent();
put("out");
if (stmnt.parameter != tok!"")
{
Expand Down Expand Up @@ -2678,7 +2678,11 @@ class Formatter(Sink)
{
foreach (contract; functionContracts)
format(contract);
put("do");
if (specifiedFunctionBody.hasDo)
{
newlineIndent();
put("do");
}
if (blockStatement)
format(blockStatement);
}
Expand Down Expand Up @@ -4144,4 +4148,95 @@ do{}
testFormatNode!(AliasDeclaration)("alias f(T) = void(int, int, int) const pure nothrow;");

testFormatNode!(AliasDeclaration)("alias MT = mixin (strEnum1, strEnum2);");

testFormatNode!(Module)("static assert(() @trusted { return bar()(3); }() == 4);",
`static assert (() @trusted
{ return bar()(3);
}() == 4)`
);
testFormatNode!(Module)("int foo() { return 2; }",
`int foo()
{
return 2;
}`
);

testFormatNode!(Module)("int foo() do { return 2; }",
`int foo()
do
{
return 2;
}`
);

testFormatNode!(Module)("int foo(int i) in(i > 0) do { return 2; }",
`int foo(int i)
in (i > 0)
do
{
return 2;
}`
);

testFormatNode!(Module)("int foo(int i) in { assert(i > 0); } do { return 2; }",
`int foo(int i)
in
{
assert (i > 0);
}
do
{
return 2;
}`
);

testFormatNode!(Module)("int foo() out(j; j > 0) do { return 2; }",
`int foo()
out (j; j > 0)
do
{
return 2;
}`
);

testFormatNode!(Module)("int foo() out(j) { assert(j > 0); } do { return 2; }",
`int foo()
out (j)
{
assert (j > 0);
}
do
{
return 2;
}`
);

testFormatNode!(Module)("version(BAR) {
int foo(int i)
in(i > 0) in { assert(i > 0); }
out(j; j > 0) out(j) { assert(j>0); }
do { return 2; } int i; }
",
`version (BAR)
{

int foo(int i)
in (i > 0)
in
{
assert (i > 0);
}
out (j; j > 0)
out (j)
{
assert (j > 0);
}
do
{
return 2;
}

int i;
}`
);
}