Import with comment behind must not output newlines

This commit is contained in:
Andreas Zwinkau 2015-01-17 00:19:51 +01:00
parent 9e7d57af84
commit cb9a4015e7
3 changed files with 51 additions and 1 deletions

View file

@ -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
View 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
View 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);
}