From 0186bc9041e94003468047768b3c2f6f29c4c4a7 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Tue, 22 Oct 2024 07:20:42 -0700 Subject: [PATCH] Test AvoidInfix w/ fold, redundant braces, `else` --- .../src/test/resources/rewrite/AvoidInfix.stat | 14 ++++++++++++++ .../src/test/scala/org/scalafmt/FormatTests.scala | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scalafmt-tests/shared/src/test/resources/rewrite/AvoidInfix.stat b/scalafmt-tests/shared/src/test/resources/rewrite/AvoidInfix.stat index dc02fcef89..6786dc58cb 100644 --- a/scalafmt-tests/shared/src/test/resources/rewrite/AvoidInfix.stat +++ b/scalafmt-tests/shared/src/test/resources/rewrite/AvoidInfix.stat @@ -727,3 +727,17 @@ object a { try (new compiler.Run).compile(sourceFiles.map(_.toString)) catch { case ex: Throwable => } } +<<< #4133 avoid infix, with arg in rewritten braces just before `else` +maxColumn = 76 +newlines.source = fold +newlines.avoidForSimpleOverflow = [tooLong, punct, slc] +rewrite.rules = [RedundantBraces, RedundantParens, AvoidInfix] +=== +def primaryConstructor: Option[MemberImpl with Constructor] = if (isClass) constructors find { _.isPrimary } else None +>>> +Idempotency violated +=> Diff (- obtained, + expected) + def primaryConstructor: Option[MemberImpl with Constructor] = +- if (isClass) constructors.find(_.isPrimary) else None ++ if (isClass) constructors.find(_.isPrimary) ++ else None diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala index bb6ac8e573..4b040951b6 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -138,7 +138,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions { val explored = Debug.explored.get() logger.debug(s"Total explored: $explored") if (!onlyUnit && !onlyManual) - assertEquals(explored, 1483242, "total explored") + assertEquals(explored, 1483317, "total explored") val results = debugResults.result() // TODO(olafur) don't block printing out test results. // I don't want to deal with scalaz's Tasks :'(