From 43cfa09e7e3546582b0a609d9d41e2c725425a37 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Mon, 24 Aug 2015 13:27:22 -0700 Subject: [PATCH] Fix #177 --- src/dfmt/formatter.d | 4 +--- tests/allman/issue0177.d.ref | 29 +++++++++++++++++++++++++++++ tests/issue0177.d | 29 +++++++++++++++++++++++++++++ tests/otbs/issue0177.d.ref | 26 ++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tests/allman/issue0177.d.ref create mode 100644 tests/issue0177.d create mode 100644 tests/otbs/issue0177.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 9d53775..317528e 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -284,10 +284,8 @@ private: immutable canAddNewline = currTokenLine - prevTokenEndLine < 1; if (prevTokenEndLine == currTokenLine || (t == tok!")" && peekIs(tok!"{"))) write(" "); - else if (t != tok!";" && t != tok!"}" && canAddNewline) - { + else if (canAddNewline || (peekIs(tok!"{") && t == tok!"}")) newline(); - } } writeToken(); immutable j = justAddedExtraNewline; diff --git a/tests/allman/issue0177.d.ref b/tests/allman/issue0177.d.ref new file mode 100644 index 0000000..05fae07 --- /dev/null +++ b/tests/allman/issue0177.d.ref @@ -0,0 +1,29 @@ +unittest +{ + { + } + // + { + } +} + +unittest +{ + { + } + // + + { + } +} + +unittest +{ + { + } + + // + + { + } +} diff --git a/tests/issue0177.d b/tests/issue0177.d new file mode 100644 index 0000000..876854f --- /dev/null +++ b/tests/issue0177.d @@ -0,0 +1,29 @@ +unittest +{ + { + } + // + { + } +} + +unittest +{ + { + } + // + + { + } +} + +unittest +{ + { + } + + // + + { + } +} diff --git a/tests/otbs/issue0177.d.ref b/tests/otbs/issue0177.d.ref new file mode 100644 index 0000000..c2bbe3c --- /dev/null +++ b/tests/otbs/issue0177.d.ref @@ -0,0 +1,26 @@ +unittest { + { + } + // + { + } +} + +unittest { + { + } + // + + { + } +} + +unittest { + { + } + + // + + { + } +}