From 7f41c8ae7f5babdac4ce7869d6f04c67701a0fcd Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Sat, 12 Jan 2019 12:25:46 +0100 Subject: [PATCH 1/2] fix array item access regression --- src/dfmt/formatter.d | 13 ++++++++++++- tests/allman/array_access.d.ref | 7 +++++++ tests/array_access.d | 4 ++++ tests/otbs/array_access.d.ref | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/allman/array_access.d.ref create mode 100644 tests/array_access.d create mode 100644 tests/otbs/array_access.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 7b5f6a5..1a13a45 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -611,6 +611,15 @@ private: indents.push(tok!"]", detail); } + else if (p == tok!"[") + { + // array item access + IndentStack.Details detail; + detail.wrap = false; + detail.temp = true; + detail.mini = true; + indents.push(tok!"]", detail); + } else if (!currentIs(tok!")") && !currentIs(tok!"]") && (linebreakHints.canFindIndex(index - 1) || (linebreakHints.length == 0 && currentLineLength > config.max_line_length))) @@ -664,7 +673,7 @@ private: indents.popWrapIndents(); if (indents.topIs(tok!"]")) { - if (!indents.topDetails.mini) + if (!indents.topDetails.mini && !indents.topDetails.temp) newline(); else indents.pop(); @@ -839,6 +848,8 @@ private: } else if (astInformation.funLitStartLocations.canFindIndex(tIndex)) { + indents.popWrapIndents(); + sBraceDepth++; if (peekBackIsOneOf(true, tok!")", tok!"identifier")) write(" "); diff --git a/tests/allman/array_access.d.ref b/tests/allman/array_access.d.ref new file mode 100644 index 0000000..7c7a6cc --- /dev/null +++ b/tests/allman/array_access.d.ref @@ -0,0 +1,7 @@ +unittest +{ + foo([ + target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1], target.value.region[1] + ]); +} diff --git a/tests/array_access.d b/tests/array_access.d new file mode 100644 index 0000000..9a96e57 --- /dev/null +++ b/tests/array_access.d @@ -0,0 +1,4 @@ +unittest +{ + foo([target.value.region[1], target.value.region[1], target.value.region[1], target.value.region[1], target.value.region[1]]); +} \ No newline at end of file diff --git a/tests/otbs/array_access.d.ref b/tests/otbs/array_access.d.ref new file mode 100644 index 0000000..7a2ac55 --- /dev/null +++ b/tests/otbs/array_access.d.ref @@ -0,0 +1,6 @@ +unittest { + foo([ + target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1], target.value.region[1] + ]); +} From bdac7361a581e91aae5f6eee21e3b419d8d6a90d Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Sat, 12 Jan 2019 12:37:06 +0100 Subject: [PATCH 2/2] Add test for issue0112 without array item --- tests/allman/issue0112_variation.d.ref | 15 +++++++++++++++ tests/issue0112_variation.d | 18 ++++++++++++++++++ tests/otbs/issue0112_variation.d.ref | 13 +++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/allman/issue0112_variation.d.ref create mode 100644 tests/issue0112_variation.d create mode 100644 tests/otbs/issue0112_variation.d.ref diff --git a/tests/allman/issue0112_variation.d.ref b/tests/allman/issue0112_variation.d.ref new file mode 100644 index 0000000..084e5eb --- /dev/null +++ b/tests/allman/issue0112_variation.d.ref @@ -0,0 +1,15 @@ +unittest +{ + testScene = new Scene(longArgument, longArgument, longArgument, + longArgument, longArgument, longArgument, delegate(Scene scene) { + import std.stdio; + + if (!scene.alreadyEntered) + { + fwriteln( + "This is a test. This is a test. This is a test. This is a test. This is a test. Test12."); + auto p = cast(Portal) sceneManager.previousScene; + scene.destroyCurrentScript(); + } + }); +} diff --git a/tests/issue0112_variation.d b/tests/issue0112_variation.d new file mode 100644 index 0000000..73e3d89 --- /dev/null +++ b/tests/issue0112_variation.d @@ -0,0 +1,18 @@ +unittest +{ + testScene = new Scene + ( + longArgument, longArgument, longArgument, longArgument, longArgument, longArgument, + delegate(Scene scene) + { + import std.stdio; + + if (!scene.alreadyEntered) + { + fwriteln("This is a test. This is a test. This is a test. This is a test. This is a test. Test12."); + auto p = cast(Portal)sceneManager.previousScene; + scene.destroyCurrentScript(); + } + } + ); +} diff --git a/tests/otbs/issue0112_variation.d.ref b/tests/otbs/issue0112_variation.d.ref new file mode 100644 index 0000000..424c1dd --- /dev/null +++ b/tests/otbs/issue0112_variation.d.ref @@ -0,0 +1,13 @@ +unittest { + testScene = new Scene(longArgument, longArgument, longArgument, + longArgument, longArgument, longArgument, delegate(Scene scene) { + import std.stdio; + + if (!scene.alreadyEntered) { + fwriteln( + "This is a test. This is a test. This is a test. This is a test. This is a test. Test12."); + auto p = cast(Portal) sceneManager.previousScene; + scene.destroyCurrentScript(); + } + }); +}