Skip to content

Commit

Permalink
TestStyles: use predefined style variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 6, 2024
1 parent 5851f7d commit 7096aaa
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.scalafmt.community.common

import org.scalafmt.config.ScalafmtConfig

import scala.meta._

abstract class CommunityRepoSuite(giturl: String, name: String)
Expand All @@ -11,20 +13,24 @@ abstract class CommunityRepoSuite(giturl: String, name: String)
files: Int,
excluded: List[String] = Nil,
fileOverride: String = null,
styles: Set[String] = Set.empty,
styles: Seq[sourcecode.Text[ScalafmtConfig]] = Seq.empty,
statsPerStyle: Map[String, TestStats.Style] = Map.empty,
statsAllStyles: Option[TestStats.Style] = None,
stylesIncluded: Boolean = true,
) = CommunityBuild(
giturl,
ref,
name,
excluded,
files,
dialect,
styles = styles,
styles = styles.map(_.source).map { x =>
x.substring(1 + x.lastIndexOf('.'))
}.toSet,
fileOverride = Option(fileOverride),
statsPerStyle = statsPerStyle,
statsAllStyles = statsAllStyles,
stylesIncluded = stylesIncluded,
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.scalafmt.rewrite._

import scala.collection.immutable.SortedMap

object TestStyles {
private[community] object TestStyles {

private val baseClassicStyle = {
val base = ScalafmtConfig.default
Expand Down Expand Up @@ -36,7 +36,8 @@ object TestStyles {
removeOptionalBraces = RewriteScala3Settings.RemoveOptionalBraces.yes,
insertEndMarkerMinLines = 5,
),
redundantBraces = RedundantBracesSettings.all,
redundantBraces = RedundantBracesSettings.all
.copy(maxBreaks = Int.MaxValue),
redundantParens = RedundantParensSettings.all,
),
)
Expand All @@ -46,16 +47,28 @@ object TestStyles {
private val baseKeepStyle = baseClassicStyle.withSource(Newlines.keep)
private val baseFoldStyle = baseClassicStyle.withSource(Newlines.fold)

val styles: Map[String, ScalafmtConfig] = SortedMap(
"classic" -> baseClassicStyle,
"classicWithRewrites" -> baseClassicStyle.withRewrites(),
"classicWithAlign" -> baseClassicStyle.withAlign(Align.most),
"keep" -> baseKeepStyle,
"keepWithRewrites" -> baseKeepStyle.withRewrites(),
"keepWithAlign" -> baseKeepStyle.withAlign(Align.most),
"keepWithScalaJS" -> baseKeepStyle.forScalaJs,
"fold" -> baseFoldStyle,
"unfold" -> baseClassicStyle.withSource(Newlines.unfold),
val classic = baseClassicStyle
val classicWithRewrites = baseClassicStyle.withRewrites()
val classicWithAlign = baseClassicStyle.withAlign(Align.most)
val keep = baseKeepStyle
val keepWithRewrites = baseKeepStyle.withRewrites()
val keepWithAlign = baseKeepStyle.withAlign(Align.most)
val keepWithScalaJS = baseKeepStyle.forScalaJs
val fold = baseFoldStyle
val unfold = baseClassicStyle.withSource(Newlines.unfold)

val stylesWithLabels = Seq[sourcecode.Text[ScalafmtConfig]](
classic,
classicWithRewrites,
classicWithAlign,
keep,
keepWithRewrites,
keepWithAlign,
keepWithScalaJS,
fold,
unfold,
)
val styles: Map[String, ScalafmtConfig] =
SortedMap(stylesWithLabels.map(x => x.source -> x.value): _*)

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class CommunityIntellijScalaSuite(name: String)
class CommunityIntellijScala_2024_2_Suite
extends CommunityIntellijScalaSuite("intellij-scala-2024.2") {

override protected def totalStatesVisited: Option[Int] = Some(47254706)
override protected def totalStatesVisited: Option[Int] = Some(47255098)

override protected def builds = Seq(getBuild(
"2024.2.28",
Expand Down Expand Up @@ -51,7 +51,7 @@ class CommunityIntellijScala_2024_2_Suite
class CommunityIntellijScala_2024_3_Suite
extends CommunityIntellijScalaSuite("intellij-scala-2024.3") {

override protected def totalStatesVisited: Option[Int] = Some(47431883)
override protected def totalStatesVisited: Option[Int] = Some(47432293)

override protected def builds = Seq(getBuild(
"2024.3.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class CommunityScala2Suite(name: String)

class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {

override protected def totalStatesVisited: Option[Int] = Some(34661248)
override protected def totalStatesVisited: Option[Int] = Some(34661412)

override protected def builds =
Seq(getBuild("v2.12.20", dialects.Scala212, 1277))
Expand All @@ -18,7 +18,7 @@ class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {

class CommunityScala2_13Suite extends CommunityScala2Suite("scala-2.13") {

override protected def totalStatesVisited: Option[Int] = Some(43184810)
override protected def totalStatesVisited: Option[Int] = Some(43185118)

override protected def builds =
Seq(getBuild("v2.13.14", dialects.Scala213, 1287))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class CommunitySparkSuite(name: String)

class CommunitySpark3_4Suite extends CommunitySparkSuite("spark-3.4") {

override protected def totalStatesVisited: Option[Int] = Some(70715532)
override protected def totalStatesVisited: Option[Int] = Some(70715816)

override protected def builds =
Seq(getBuild("v3.4.1", dialects.Scala213, 2585))
Expand All @@ -18,7 +18,7 @@ class CommunitySpark3_4Suite extends CommunitySparkSuite("spark-3.4") {

class CommunitySpark3_5Suite extends CommunitySparkSuite("spark-3.5") {

override protected def totalStatesVisited: Option[Int] = Some(74807885)
override protected def totalStatesVisited: Option[Int] = Some(74808431)

override protected def builds =
Seq(getBuild("v3.5.3", dialects.Scala213, 2756))
Expand Down

0 comments on commit 7096aaa

Please sign in to comment.