fix windows/mac linebreaks

This commit is contained in:
Cameron Ross 2018-07-31 15:08:07 -03:00
parent 1448c8fe86
commit d4ed861920
No known key found for this signature in database
GPG key ID: 777897D98DC91C54
2 changed files with 27 additions and 2 deletions

View file

@ -319,3 +319,28 @@ struct Dumper(Range)
//account for newline at end //account for newline at end
assert(stream.data[$-4..$-1] != "..."); assert(stream.data[$-4..$-1] != "...");
} }
// Windows, macOS line breaks
@safe unittest
{
auto node = Node(0);
{
auto stream = new Appender!string();
auto dumper = dumper(stream);
dumper.explicitEnd = true;
dumper.explicitStart = true;
dumper.YAMLVersion = null;
dumper.lineBreak = LineBreak.Windows;
dumper.dump(node);
assert(stream.data == "--- 0\r\n...\r\n");
}
{
auto stream = new Appender!string();
auto dumper = dumper(stream);
dumper.explicitEnd = true;
dumper.explicitStart = true;
dumper.YAMLVersion = null;
dumper.lineBreak = LineBreak.Macintosh;
dumper.dump(node);
assert(stream.data == "--- 0\r...\r");
}
}

View file

@ -26,7 +26,7 @@ string lineBreak(in LineBreak b) pure @safe nothrow
final switch(b) final switch(b)
{ {
case LineBreak.Unix: return "\n"; case LineBreak.Unix: return "\n";
case LineBreak.Windows: return "\r"; case LineBreak.Windows: return "\r\n";
case LineBreak.Macintosh: return "\r\n"; case LineBreak.Macintosh: return "\r";
} }
} }