From b5dbb0e031d411bb94c8784f52eebbe474583755 Mon Sep 17 00:00:00 2001 From: Mathis Beer Date: Mon, 6 Jul 2020 14:25:53 +0200 Subject: [PATCH] Fix issue 483: indent continuing case statements on the same level --- src/dfmt/formatter.d | 9 ++++++++- tests/allman/issue0483.d.ref | 15 +++++++++++++++ tests/issue0483.args | 1 + tests/issue0483.d | 15 +++++++++++++++ tests/otbs/issue0483.d.ref | 13 +++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/allman/issue0483.d.ref create mode 100644 tests/issue0483.args create mode 100644 tests/issue0483.d create mode 100644 tests/otbs/issue0483.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index ae3f798..4017870 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -1715,7 +1715,14 @@ private: } else if (currentIs(tok!"case") || currentIs(tok!"default")) { - if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true)) + + if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true) + /** + * The following code is valid and should be indented flatly + * case A: + * case B: + */ + || peekBackIs(tok!":", true)) { indents.popTempIndents(); if (indents.topIs(tok!"case")) diff --git a/tests/allman/issue0483.d.ref b/tests/allman/issue0483.d.ref new file mode 100644 index 0000000..1d77e68 --- /dev/null +++ b/tests/allman/issue0483.d.ref @@ -0,0 +1,15 @@ +module tests.issue0483; + +void main() +{ + switch (0) + { + case 1: + case 2: + label: + case 3: + break; + default: + break; + } +} diff --git a/tests/issue0483.args b/tests/issue0483.args new file mode 100644 index 0000000..91e2439 --- /dev/null +++ b/tests/issue0483.args @@ -0,0 +1 @@ +--align_switch_statements=false diff --git a/tests/issue0483.d b/tests/issue0483.d new file mode 100644 index 0000000..1d77e68 --- /dev/null +++ b/tests/issue0483.d @@ -0,0 +1,15 @@ +module tests.issue0483; + +void main() +{ + switch (0) + { + case 1: + case 2: + label: + case 3: + break; + default: + break; + } +} diff --git a/tests/otbs/issue0483.d.ref b/tests/otbs/issue0483.d.ref new file mode 100644 index 0000000..b23c692 --- /dev/null +++ b/tests/otbs/issue0483.d.ref @@ -0,0 +1,13 @@ +module tests.issue0483; + +void main() { + switch (0) { + case 1: + case 2: + label: + case 3: + break; + default: + break; + } +}