From d4ed861920c3389b64777904c933b58b20cb94f6 Mon Sep 17 00:00:00 2001 From: Cameron Ross Date: Tue, 31 Jul 2018 15:08:07 -0300 Subject: [PATCH] fix windows/mac linebreaks --- source/dyaml/dumper.d | 25 +++++++++++++++++++++++++ source/dyaml/linebreak.d | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/source/dyaml/dumper.d b/source/dyaml/dumper.d index 0e4d63e..1afd082 100644 --- a/source/dyaml/dumper.d +++ b/source/dyaml/dumper.d @@ -319,3 +319,28 @@ struct Dumper(Range) //account for newline at end 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"); + } +} diff --git a/source/dyaml/linebreak.d b/source/dyaml/linebreak.d index 97ef125..26ba609 100644 --- a/source/dyaml/linebreak.d +++ b/source/dyaml/linebreak.d @@ -26,7 +26,7 @@ string lineBreak(in LineBreak b) pure @safe nothrow final switch(b) { case LineBreak.Unix: return "\n"; - case LineBreak.Windows: return "\r"; - case LineBreak.Macintosh: return "\r\n"; + case LineBreak.Windows: return "\r\n"; + case LineBreak.Macintosh: return "\r"; } }