From 8c6e4475790a84aed30ca29c4c4c88e54ac4ca20 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 23 Nov 2024 08:22:04 -0800 Subject: [PATCH] Test select with apply in braces and single func --- .../resources/newlines/source_classic.stat | 34 ++++++++++++++ .../test/resources/newlines/source_fold.stat | 33 ++++++++++++++ .../test/resources/newlines/source_keep.stat | 34 ++++++++++++++ .../resources/newlines/source_unfold.stat | 36 +++++++++++++++ .../test/resources/scala3/OptionalBraces.stat | 39 ++++++++++++++++ .../resources/scala3/OptionalBraces_fold.stat | 34 ++++++++++++++ .../resources/scala3/OptionalBraces_keep.stat | 39 ++++++++++++++++ .../scala3/OptionalBraces_unfold.stat | 44 +++++++++++++++++++ .../test/scala/org/scalafmt/FormatTests.scala | 2 +- 9 files changed, 294 insertions(+), 1 deletion(-) diff --git a/scalafmt-tests/shared/src/test/resources/newlines/source_classic.stat b/scalafmt-tests/shared/src/test/resources/newlines/source_classic.stat index 7c6bcb3c9..1cdc23159 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source_classic.stat +++ b/scalafmt-tests/shared/src/test/resources/newlines/source_classic.stat @@ -11291,3 +11291,37 @@ object a { quux(x) } } +<<< #4133 select with braced apply and single function arg, !parensForOneLineApply +maxColumn = 74 +newlines { + avoidForSimpleOverflow = [punct, slc, tooLong] + ignoreInSyntax = false +} +rewrite.rules = [RedundantBraces] +rewrite.redundantBraces.parensForOneLineApply = false +=== + topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +>>> +topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { + x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) +} +<<< #4133 select with braced apply and single function arg, parensForOneLineApply +maxColumn = 74 +newlines { + avoidForSimpleOverflow = [punct, slc, tooLong] + ignoreInSyntax = false +} +rewrite.rules = [RedundantBraces] +rewrite.redundantBraces.parensForOneLineApply = true +=== + topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +>>> +topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { + x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) +} diff --git a/scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat b/scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat index 23a3b3ce9..93a12efd1 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat +++ b/scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat @@ -10532,3 +10532,36 @@ object a { quux(x) } } +<<< #4133 select with braced apply and single function arg, !parensForOneLineApply +maxColumn = 74 +newlines { + avoidForSimpleOverflow = [punct, slc, tooLong] + ignoreInSyntax = false +} +rewrite.rules = [RedundantBraces] +rewrite.redundantBraces.parensForOneLineApply = false +=== + topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +>>> +topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { + x => (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) +} +<<< #4133 select with braced apply and single function arg, parensForOneLineApply +maxColumn = 74 +newlines { + avoidForSimpleOverflow = [punct, slc, tooLong] + ignoreInSyntax = false +} +rewrite.rules = [RedundantBraces] +rewrite.redundantBraces.parensForOneLineApply = true +=== + topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +>>> +topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest) + .sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } diff --git a/scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat b/scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat index a19dd2a15..c7d56c404 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat +++ b/scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat @@ -11043,3 +11043,37 @@ object a { quux(x) } } +<<< #4133 select with braced apply and single function arg, !parensForOneLineApply +maxColumn = 74 +newlines { + avoidForSimpleOverflow = [punct, slc, tooLong] + ignoreInSyntax = false +} +rewrite.rules = [RedundantBraces] +rewrite.redundantBraces.parensForOneLineApply = false +=== + topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +>>> +topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { + x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) +} +<<< #4133 select with braced apply and single function arg, parensForOneLineApply +maxColumn = 74 +newlines { + avoidForSimpleOverflow = [punct, slc, tooLong] + ignoreInSyntax = false +} +rewrite.rules = [RedundantBraces] +rewrite.redundantBraces.parensForOneLineApply = true +=== + topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +>>> +topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { + x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) +} diff --git a/scalafmt-tests/shared/src/test/resources/newlines/source_unfold.stat b/scalafmt-tests/shared/src/test/resources/newlines/source_unfold.stat index bb241988e..ff1ad0be3 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source_unfold.stat +++ b/scalafmt-tests/shared/src/test/resources/newlines/source_unfold.stat @@ -11471,3 +11471,39 @@ object a { quux(x) } } +<<< #4133 select with braced apply and single function arg, !parensForOneLineApply +maxColumn = 74 +newlines { + avoidForSimpleOverflow = [punct, slc, tooLong] + ignoreInSyntax = false +} +rewrite.rules = [RedundantBraces] +rewrite.redundantBraces.parensForOneLineApply = false +=== + topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +>>> +topLevelStatementBlankLines + .filter(x => x.minNest <= x.maxNest) + .sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +<<< #4133 select with braced apply and single function arg, parensForOneLineApply +maxColumn = 74 +newlines { + avoidForSimpleOverflow = [punct, slc, tooLong] + ignoreInSyntax = false +} +rewrite.rules = [RedundantBraces] +rewrite.redundantBraces.parensForOneLineApply = true +=== + topLevelStatementBlankLines.filter(x => x.minNest <= x.maxNest).sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } +>>> +topLevelStatementBlankLines + .filter(x => x.minNest <= x.maxNest) + .sortBy { x => + (x.minBreaks, x.maxNest, -x.minNest, x.regex.fold(0)(-_.length)) + } diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat index b4a0d0faa..f976cc7e7 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat @@ -7840,3 +7840,42 @@ object a: >>> object a: def func(f: ->{a, b, c} B): Unit +<<< #4133 select with braced apply and single function arg, within interpolation +maxColumn = 70 +rewrite.rules = [RedundantBraces] +=== +s"`$name0${index.toString.toCharArray.nn.map {x => (x - '0' + '₀').toChar}.mkString}`" +>>> +s"`$name0${index.toString.toCharArray.nn.map { x => + (x - '0' + '₀').toChar + }.mkString}`" +<<< #4133 select with braced apply, single function arg in second clause +maxColumn = 66 +rewrite.rules = [RedundantBraces] +=== +next.fold { + resultsDiv.appendChild(m.toHTML) +} { next => + resultsDiv.insertBefore(m.toHTML, next) +} +>>> +next.fold { + resultsDiv.appendChild(m.toHTML) +} { next => + resultsDiv.insertBefore(m.toHTML, next) +} +<<< #4133 select with braced apply, single function arg, within another apply +maxColumn = 66 +rewrite.rules = [RedundantBraces] +=== +lazy val onlyImplicitOrTypeParams = paramss.forall( + _.exists { sym => + sym.isType || sym.is(Implicit) || sym.is(Given) + } +) +>>> +lazy val onlyImplicitOrTypeParams = paramss.forall( + _.exists { sym => + sym.isType || sym.is(Implicit) || sym.is(Given) + } +) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat index dfbd5e514..fafb4244a 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat @@ -7539,3 +7539,37 @@ object a: >>> object a: def func(f: ->{a, b, c} B): Unit +<<< #4133 select with braced apply and single function arg, within interpolation +maxColumn = 70 +rewrite.rules = [RedundantBraces] +=== +s"`$name0${index.toString.toCharArray.nn.map {x => (x - '0' + '₀').toChar}.mkString}`" +>>> +s"`$name0${index.toString.toCharArray.nn + .map(x => (x - '0' + '₀').toChar).mkString}`" +<<< #4133 select with braced apply, single function arg in second clause +maxColumn = 66 +rewrite.rules = [RedundantBraces] +=== +next.fold { + resultsDiv.appendChild(m.toHTML) +} { next => + resultsDiv.insertBefore(m.toHTML, next) +} +>>> +next.fold(resultsDiv.appendChild(m.toHTML)) { next => + resultsDiv.insertBefore(m.toHTML, next) +} +<<< #4133 select with braced apply, single function arg, within another apply +maxColumn = 66 +rewrite.rules = [RedundantBraces] +=== +lazy val onlyImplicitOrTypeParams = paramss.forall( + _.exists { sym => + sym.isType || sym.is(Implicit) || sym.is(Given) + } +) +>>> +lazy val onlyImplicitOrTypeParams = paramss.forall(_.exists { sym => + sym.isType || sym.is(Implicit) || sym.is(Given) +}) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat index ce1de549a..d4b2ca4e2 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat @@ -7864,3 +7864,42 @@ object a: >>> object a: def func(f: ->{a, b, c} B): Unit +<<< #4133 select with braced apply and single function arg, within interpolation +maxColumn = 70 +rewrite.rules = [RedundantBraces] +=== +s"`$name0${index.toString.toCharArray.nn.map {x => (x - '0' + '₀').toChar}.mkString}`" +>>> +s"`$name0${index.toString.toCharArray.nn.map { x => + (x - '0' + '₀').toChar + }.mkString}`" +<<< #4133 select with braced apply, single function arg in second clause +maxColumn = 66 +rewrite.rules = [RedundantBraces] +=== +next.fold { + resultsDiv.appendChild(m.toHTML) +} { next => + resultsDiv.insertBefore(m.toHTML, next) +} +>>> +next.fold { + resultsDiv.appendChild(m.toHTML) +} { next => + resultsDiv.insertBefore(m.toHTML, next) +} +<<< #4133 select with braced apply, single function arg, within another apply +maxColumn = 66 +rewrite.rules = [RedundantBraces] +=== +lazy val onlyImplicitOrTypeParams = paramss.forall( + _.exists { sym => + sym.isType || sym.is(Implicit) || sym.is(Given) + } +) +>>> +lazy val onlyImplicitOrTypeParams = paramss.forall( + _.exists { sym => + sym.isType || sym.is(Implicit) || sym.is(Given) + } +) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat index 711cc3daa..1675e854c 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -8158,3 +8158,47 @@ object a: >>> object a: def func(f: ->{a, b, c} B): Unit +<<< #4133 select with braced apply and single function arg, within interpolation +maxColumn = 70 +rewrite.rules = [RedundantBraces] +=== +s"`$name0${index.toString.toCharArray.nn.map {x => (x - '0' + '₀').toChar}.mkString}`" +>>> +s"`$name0${index + .toString + .toCharArray + .nn + .map { x => + (x - '0' + '₀').toChar + } + .mkString}`" +<<< #4133 select with braced apply, single function arg in second clause +maxColumn = 66 +rewrite.rules = [RedundantBraces] +=== +next.fold { + resultsDiv.appendChild(m.toHTML) +} { next => + resultsDiv.insertBefore(m.toHTML, next) +} +>>> +next.fold { + resultsDiv.appendChild(m.toHTML) +} { next => + resultsDiv.insertBefore(m.toHTML, next) +} +<<< #4133 select with braced apply, single function arg, within another apply +maxColumn = 66 +rewrite.rules = [RedundantBraces] +=== +lazy val onlyImplicitOrTypeParams = paramss.forall( + _.exists { sym => + sym.isType || sym.is(Implicit) || sym.is(Given) + } +) +>>> +lazy val onlyImplicitOrTypeParams = paramss.forall( + _.exists { sym => + sym.isType || sym.is(Implicit) || sym.is(Given) + } +) 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 2814e6449..9fb812073 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -144,7 +144,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, 1183640, "total explored") + assertEquals(explored, 1186090, "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 :'(