From 08c2d0c5e8d01a6b3e206b675cd14b5c60ee10ea Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Thu, 21 Jan 2016 22:11:32 -0800 Subject: [PATCH] Fix #222 --- src/dfmt/formatter.d | 4 +++- tests/allman/issue0222.d.ref | 5 +++++ tests/issue0222.d | 6 ++++++ tests/otbs/issue0222.d.ref | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/allman/issue0222.d.ref create mode 100644 tests/issue0222.d create mode 100644 tests/otbs/issue0222.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index cf8d9ab..d18a328 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -364,7 +364,9 @@ private: immutable canAddNewline = currTokenLine - prevTokenEndLine < 1; if (peekBackIsOperator() && !isSeparationToken(t)) pushWrapIndent(t); - if (peekBackIs(tok!")") && !canAddNewline && prevTokenEndLine < currTokenLine) + if (peekBackIsOperator() && !peekBackIsOneOf(false, tok!"comment", + tok!"{", tok!"}", tok!":", tok!";", tok!",", tok!"[", tok!"(") + && !canAddNewline && prevTokenEndLine < currTokenLine) write(" "); else if (prevTokenEndLine == currTokenLine || (t == tok!")" && peekIs(tok!"{"))) write(" "); diff --git a/tests/allman/issue0222.d.ref b/tests/allman/issue0222.d.ref new file mode 100644 index 0000000..c9bce8b --- /dev/null +++ b/tests/allman/issue0222.d.ref @@ -0,0 +1,5 @@ +unittest +{ + return (complicated % expression) / //------------------- + (other * complicated + expression); +} diff --git a/tests/issue0222.d b/tests/issue0222.d new file mode 100644 index 0000000..d8cdc87 --- /dev/null +++ b/tests/issue0222.d @@ -0,0 +1,6 @@ +unittest +{ + return (complicated % expression) / + //------------------- + (other * complicated + expression); +} diff --git a/tests/otbs/issue0222.d.ref b/tests/otbs/issue0222.d.ref new file mode 100644 index 0000000..09a8058 --- /dev/null +++ b/tests/otbs/issue0222.d.ref @@ -0,0 +1,4 @@ +unittest { + return (complicated % expression) / //------------------- + (other * complicated + expression); +}