From 85247f77f721a4b147a3fa1c8682940d12719f9e Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Sat, 7 Mar 2015 18:30:19 -0800 Subject: [PATCH] Fix #43 --- src/dfmt.d | 31 ++++++++++++++++++++++++++----- tests/issue0043.d | 12 ++++++++++++ tests/issue0043.d.ref | 15 +++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 tests/issue0043.d create mode 100644 tests/issue0043.d.ref diff --git a/src/dfmt.d b/src/dfmt.d index df9a8df..a795cfc 100644 --- a/src/dfmt.d +++ b/src/dfmt.d @@ -816,6 +816,12 @@ private: writeToken(); // switch write(" "); writeParens(true); + if (current.type == tok!"with") + { + writeToken(); + write(" "); + writeParens(true); + } if (current.type != tok!"{") return; if (config.braceStyle == BraceStyle.otbs) @@ -853,12 +859,27 @@ private: writeToken(); write(" "); } - else if (current.type == tok!":" && peekIs(tok!"..")) + else if (current.type == tok!":") { - writeToken(); - write(" "); - writeToken(); - write(" "); + if (peekIs(tok!"..")) + { + writeToken(); + write(" "); + writeToken(); + write(" "); + } + else if (peekIs(tok!"identifier") && peek2Is(tok!":")) + { + writeToken(); + indentLevel++; + newline(); + writeToken(); + writeToken(); + indentLevel++; + newline(); + } + else + goto peek; } else { diff --git a/tests/issue0043.d b/tests/issue0043.d new file mode 100644 index 0000000..df9f8ad --- /dev/null +++ b/tests/issue0043.d @@ -0,0 +1,12 @@ +unittest +{ + switch (something) with (stuff){ + case 1: case 2: +label:doStuff(); + case 3: + doOtherSTuff(); + goto label; +default: +break; +} +} diff --git a/tests/issue0043.d.ref b/tests/issue0043.d.ref new file mode 100644 index 0000000..4f171c4 --- /dev/null +++ b/tests/issue0043.d.ref @@ -0,0 +1,15 @@ +unittest +{ + switch (something) with (stuff) + { + case 1: + case 2: + label: + doStuff(); + case 3: + doOtherSTuff(); + goto label; + default: + break; + } +}