mirror of
https://github.com/dlang-community/dfmt.git
synced 2025-04-25 21:00:03 +03:00
Import with comment behind must not output newlines
This commit is contained in:
parent
9e7d57af84
commit
cb9a4015e7
3 changed files with 51 additions and 1 deletions
|
@ -159,7 +159,7 @@ private:
|
|||
const i = index;
|
||||
if (i > 0)
|
||||
{
|
||||
if (tokens[i-1].line < tokens[i].line)
|
||||
if (tokens[i-1].line < current.line)
|
||||
{
|
||||
if (tokens[i-1].type != tok!"comment"
|
||||
&& tokens[i-1].type != tok!"{")
|
||||
|
@ -192,6 +192,8 @@ private:
|
|||
{
|
||||
writeToken();
|
||||
tempIndent = 0;
|
||||
if (current.type == tok!"comment")
|
||||
break;
|
||||
if (!(t == tok!"import" && current.type == tok!"import"))
|
||||
write("\n");
|
||||
newline();
|
||||
|
|
24
tests/swap.d
Normal file
24
tests/swap.d
Normal file
|
@ -0,0 +1,24 @@
|
|||
import std.algorithm: swap; // from Phobos standard library
|
||||
|
||||
// The D solution uses templates and it's similar to the C++ one:
|
||||
void mySwap(T)(ref T left, ref T right) {
|
||||
auto temp = left;
|
||||
left = right;
|
||||
right = temp;
|
||||
}
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
|
||||
int[] a = [10, 20];
|
||||
writeln(a);
|
||||
|
||||
// The std.algorithm standard library module
|
||||
// contains a generic swap:
|
||||
swap(a[0], a[1]);
|
||||
writeln(a);
|
||||
|
||||
// Using mySwap:
|
||||
mySwap(a[0], a[1]);
|
||||
writeln(a);
|
||||
}
|
24
tests/swap.d.ref
Normal file
24
tests/swap.d.ref
Normal file
|
@ -0,0 +1,24 @@
|
|||
import std.algorithm : swap; // from Phobos standard library
|
||||
|
||||
// The D solution uses templates and it's similar to the C++ one:
|
||||
void mySwap(T)(ref T left, ref T right)
|
||||
{
|
||||
auto temp = left;
|
||||
left = right;
|
||||
right = temp;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
import std.stdio;
|
||||
|
||||
int[] a = [10, 20];
|
||||
writeln(a);
|
||||
// The std.algorithm standard library module
|
||||
// contains a generic swap:
|
||||
swap(a[0], a[1]);
|
||||
writeln(a);
|
||||
// Using mySwap:
|
||||
mySwap(a[0], a[1]);
|
||||
writeln(a);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue