From 1915a5568f9a8791708f2b1d27742d71ba5cbb6e Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Tue, 5 Nov 2024 12:00:12 -0800 Subject: [PATCH] TestStyles: add [un]foldWithRewritesAndOverflow --- .../org/scalafmt/community/common/TestStyles.scala | 12 +++++++++++- .../community/other/CommunityScalaJsSuite.scala | 10 ++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/TestStyles.scala b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/TestStyles.scala index e448977ec3..7387f6282a 100644 --- a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/TestStyles.scala +++ b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/TestStyles.scala @@ -42,10 +42,14 @@ private[community] object TestStyles { ), ) + def withOverflow(types: Newlines.AvoidForSimpleOverflow*): ScalafmtConfig = + style.copy(newlines = style.newlines.copy(avoidForSimpleOverflow = types)) + } private val baseKeepStyle = baseClassicStyle.withSource(Newlines.keep) private val baseFoldStyle = baseClassicStyle.withSource(Newlines.fold) + private val baseUnfoldStyle = baseClassicStyle.withSource(Newlines.unfold) val classic = baseClassicStyle val classicWithRewrites = baseClassicStyle.withRewrites() @@ -55,7 +59,11 @@ private[community] object TestStyles { val keepWithAlign = baseKeepStyle.withAlign(Align.most) val keepWithScalaJS = baseKeepStyle.forScalaJs val fold = baseFoldStyle - val unfold = baseClassicStyle.withSource(Newlines.unfold) + val foldWithRewritesAndOverflow = baseFoldStyle.withRewrites() + .withOverflow(Newlines.AvoidForSimpleOverflow.all.map(_.value): _*) + val unfold = baseUnfoldStyle + val unfoldWithRewritesAndOverflow = baseUnfoldStyle.withRewrites() + .withOverflow(Newlines.AvoidForSimpleOverflow.all.map(_.value): _*) val stylesWithLabels = Seq[sourcecode.Text[ScalafmtConfig]]( classic, @@ -66,7 +74,9 @@ private[community] object TestStyles { keepWithAlign, keepWithScalaJS, fold, + foldWithRewritesAndOverflow, unfold, + unfoldWithRewritesAndOverflow, ) val styles: Map[String, ScalafmtConfig] = SortedMap(stylesWithLabels.map(x => x.source -> x.value): _*) diff --git a/scalafmt-tests-community/other/src/test/scala/org/scalafmt/community/other/CommunityScalaJsSuite.scala b/scalafmt-tests-community/other/src/test/scala/org/scalafmt/community/other/CommunityScalaJsSuite.scala index 4bbcefecc9..1b1811560e 100644 --- a/scalafmt-tests-community/other/src/test/scala/org/scalafmt/community/other/CommunityScalaJsSuite.scala +++ b/scalafmt-tests-community/other/src/test/scala/org/scalafmt/community/other/CommunityScalaJsSuite.scala @@ -1,6 +1,7 @@ package org.scalafmt.community.other import org.scalafmt.community.common.CommunityRepoSuite +import org.scalafmt.community.common.TestStyles import scala.meta._ @@ -9,7 +10,12 @@ abstract class CommunityScalaJsSuite(name: String) class CommunityScalaJs1_17Suite extends CommunityScalaJsSuite("scala-js-1.17") { - override protected def builds = - Seq(getBuild("v1.17.0", dialects.Scala213, 787)) + override protected def builds = Seq(getBuild( + "v1.17.0", + dialects.Scala213, + 787, + styles = Seq(TestStyles.foldWithRewritesAndOverflow), + stylesIncluded = false, + )) }