D-Programming-Language/dmd — pull request #1641 by AndrejMitrovic (2013-02-08 14:47:26+00:00)
Title: Issue 9475 - Preserve code layout in unittest body when emitting ddoc.

http://d.puremagic.com/issues/show_bug.cgi?id=9475

This is a **partial** implementation, do not pull it yet.

A problem remains, the ddoc output ends up retaining the original indentation of the body of the unittest, for example:

```D
// comment 1
foreach (i; 0 .. 10)
{
// comment 2
documentedFunction();
}
```

However what is preferred is to unindent the code by the amount of indentation detected in the string, the result of which should be:

```D
// comment 1
foreach (i; 0 .. 10)
{
// comment 2
documentedFunction();
}
```

But this isn't trivial to implement. Indentation has to be detected properly (there could be mixed tabs+spaces). So I'm gonna need a helping hand here to implement this properly.

**Btw**, the reason the unittest body string is extracted eagerly in `Parser::parseUnitTest` rather than in `emitUnittestComment`, is because by the time `emitUnittestComment` is ran the lexer ends up freeing the memory.