From 9e3f58afbaf08236d05cb486a47a14fd151cdcfc Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 5 Oct 2024 08:02:57 -0700 Subject: [PATCH 1/2] HasTests: parse and assert expected state visits --- .../test/scala/org/scalafmt/FormatTests.scala | 25 +++++++++++++++- .../scala/org/scalafmt/util/DiffTest.scala | 2 ++ .../scala/org/scalafmt/util/HasTests.scala | 29 ++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) 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 11d7ebf4b3..7dc1090961 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -55,14 +55,37 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions { case Left(e) => throw FormatException(e, t.original) case Right(code) => code } - def assertObtained(implicit loc: munit.Location) = + def assertVisits( + dbg1: Debug, + visitsOpt1: Option[Int], + dbgOpt2: Option[Debug], + visitsOpt2: Option[Int], + )(implicit loc: munit.Location) = dbg1.completedEvent + .foreach { completedEvent => + val actual1 = completedEvent.totalExplored + val actual2 = dbgOpt2.flatMap(_.completedEvent) + .fold(actual1)(_.totalExplored) + val actual = (actual1, actual2) + def error = s"stateVisits = $actual1, stateVisits2 = $actual2" + visitsOpt1 match { + case Some(visits1) => + val expected = (visits1, visitsOpt2.getOrElse(visits1)) + assertEquals(actual, expected, error) + case None => + } + } + var debug2Opt: Option[Debug] = None + def assertObtained(implicit loc: munit.Location) = { assertEquals(obtained, t.expected) + assertVisits(debug, t.stateVisits, debug2Opt, t.stateVisits2) + } debugResults += saveResult(t, obtained, debug) if (resultEither.isLeft) { assertObtained return } val debug2 = new Debug(onlyOne) + debug2Opt = Some(debug2) val result2 = Scalafmt.formatCode( obtained, t.style.copy(runner = scalafmtRunner(runner, debug2)), diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/DiffTest.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/DiffTest.scala index ffb94ba8de..c8b91a8062 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/DiffTest.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/DiffTest.scala @@ -16,6 +16,8 @@ case class DiffTest( skip: Boolean, only: Boolean, style: ScalafmtConfig, + stateVisits: Option[Int] = None, + stateVisits2: Option[Int] = None, ) { val file = DiffTest.testDir.relativize(Paths.get(loc.path)).toString val fullName = s"$file:${loc.line}: $name" diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/HasTests.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/HasTests.scala index 0a22484306..0e702601ba 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/HasTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/HasTests.scala @@ -2,6 +2,7 @@ package org.scalafmt.util import org.scalafmt.Debug import org.scalafmt.Scalafmt +import org.scalafmt.config.ConfParsed import org.scalafmt.config.DanglingParentheses import org.scalafmt.config.FormatEvent._ import org.scalafmt.config.Indents @@ -19,6 +20,8 @@ import java.util.regex.Pattern import scala.annotation.tailrec import scala.collection.mutable +import metaconfig.Conf +import metaconfig.Configured import munit.Assertions._ import munit.Location @@ -117,9 +120,31 @@ trait HasTests extends FormatAssertions { val name = matcher.group(1) val extraConfig = Option(matcher.group(2)) val original = matcher.group(3) - val altFilename = Option(matcher.group(4)) + val extra = Option(matcher.group(4)).flatMap { x => + ConfParsed.fromString(x).conf match { + case Configured.Ok(v) => Some(v) + case _ => Some(Conf.Str(x)) + } + } val expected = matcher.group(5) val testStyle = extraConfig.fold(style)(loadStyle(_, style, linenum)) + + val altFilename = extra match { + case Some(Conf.Str(value)) => Some(value) + case Some(x: Conf.Obj) => x.field("filename") match { + case Some(Conf.Str(value)) => Some(value) + case _ => None + } + case _ => None + } + def getExtraNum(field: String) = extra match { + case Some(x: Conf.Obj) => x.field(field) match { + case Some(Conf.Num(value)) => Some(value.intValue) + case _ => None + } + case _ => None + } + val actualName = stripPrefix(name) val test = DiffTest( actualName, @@ -130,6 +155,8 @@ trait HasTests extends FormatAssertions { moduleSkip || isSkip(name), moduleOnly || isOnly(name), testStyle, + stateVisits = getExtraNum("stateVisits"), + stateVisits2 = getExtraNum("stateVisits2"), ) linenum += numLines(t) test From 9b3f5ac02c0c4276b49f88ec294240b6f94524ec Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 5 Oct 2024 08:21:24 -0700 Subject: [PATCH 2/2] Tests: add state-visit asserts for cases w/ > 800 --- .../test/resources/binPack/LiteralList.stat | 2 +- .../src/test/resources/default/Advanced.stat | 12 ++++++------ .../src/test/resources/default/Apply.stat | 10 +++++----- .../test/resources/default/Idempotency.stat | 6 +++--- .../src/test/resources/default/Lambda.stat | 2 +- .../test/resources/default/SearchState.stat | 6 +++--- .../src/test/resources/default/Unindent.stat | 2 +- .../src/test/resources/newlines/source.source | 2 +- .../resources/newlines/source_classic.stat | 10 +++++----- .../test/resources/newlines/source_fold.stat | 18 +++++++++--------- .../test/resources/newlines/source_unfold.stat | 6 +++--- .../resources/rewrite/RedundantParens.stat | 4 ++-- .../test/resources/scala3/OptionalBraces.stat | 4 ++-- .../resources/scala3/OptionalBraces_fold.stat | 8 ++++---- .../resources/scala3/OptionalBraces_keep.stat | 2 +- .../scala3/OptionalBraces_unfold.stat | 4 ++-- .../src/test/resources/scalajs/Apply.stat | 2 +- .../src/test/resources/scalajs/DefDef.stat | 4 ++-- .../src/test/resources/unit/TermApply.stat | 2 +- .../test/scala/org/scalafmt/FormatTests.scala | 5 ++++- 20 files changed, 57 insertions(+), 54 deletions(-) diff --git a/scalafmt-tests/shared/src/test/resources/binPack/LiteralList.stat b/scalafmt-tests/shared/src/test/resources/binPack/LiteralList.stat index 0fa299e03d..0458a99d3c 100644 --- a/scalafmt-tests/shared/src/test/resources/binPack/LiteralList.stat +++ b/scalafmt-tests/shared/src/test/resources/binPack/LiteralList.stat @@ -29,7 +29,7 @@ val secret: List[Bit] = List(0, 0, 1, 1, 1, // evil comment 1, 1, 1, 1, 1, 1, 1, 1, 1, 25, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 25, 2, 2, 2, 2, 2, 2, 2, 2) ->>> +>>> { stateVisits = 846, stateVisits2 = 846 } private[this] lazy val charTypesFirst256 = Array[scala.Byte](15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 12, 24, 24, 24, 26, 24, 24, 24, 21, 22, diff --git a/scalafmt-tests/shared/src/test/resources/default/Advanced.stat b/scalafmt-tests/shared/src/test/resources/default/Advanced.stat index 563e9c5347..3118cd9ef5 100644 --- a/scalafmt-tests/shared/src/test/resources/default/Advanced.stat +++ b/scalafmt-tests/shared/src/test/resources/default/Advanced.stat @@ -47,7 +47,7 @@ val createAsStat = if (semantics.asInstanceOfs == Unchecked) { } }))) } ->>> +>>> { stateVisits = 1351 } val createAsStat = if (semantics.asInstanceOfs == Unchecked) { js.Skip() } else { @@ -206,7 +206,7 @@ options.testFilter match { }, { // else callStatement })(jstpe.AnyType) ->>> +>>> { stateVisits = 1739, stateVisits2 = 1727 } callStatement = js.If( genIsInstanceOf(callTrg, rtClass.tpe), { if (implMethodSym.owner == ObjectClass) { @@ -287,7 +287,7 @@ val ctorParamDefs = usedCtorParams map { p => js.Closure(ctorParamDefs, patchedParams, patchedBody, capturedArgs) } } ->>> +>>> { stateVisits = 1259 } withNewLocalNameScope { if (isThisFunction) { val thisParam :: actualParams = patchedParams @@ -377,7 +377,7 @@ private def withNewLocalDefs = { })) })) } ->>> +>>> { stateVisits = 3779 } val createIsArrayOfStat = { envFieldDef( "isArrayOf", @@ -456,7 +456,7 @@ js.Function(List(objParam, depthParam), js.Return { depth) }) }) ->>> +>>> { stateVisits = 1712, stateVisits2 = 1738 } js.Function(List(objParam, depthParam), js.Return { js.If(js.Apply(envField("isArrayOf", className), @@ -529,7 +529,7 @@ js.Function(List(objParam, depthParam), uri.getRawQuery(), uri.getRawFragment()).normalize() } ->>> +>>> { stateVisits = 1709 } if (uri.isAbsolute() || this.isOpaque()) uri else if ( uri._scheme.isEmpty && uri._authority.isEmpty && diff --git a/scalafmt-tests/shared/src/test/resources/default/Apply.stat b/scalafmt-tests/shared/src/test/resources/default/Apply.stat index cdff825cb4..ac1fe126ef 100644 --- a/scalafmt-tests/shared/src/test/resources/default/Apply.stat +++ b/scalafmt-tests/shared/src/test/resources/default/Apply.stat @@ -5,7 +5,7 @@ List(Split(Space, 0).withPolicy(SingleLineBlock(close)), case Decision(t@FormatToken(_, `close`, _), s) => Decision(t, List(Split(Newline, 0))) }).withIndent(2, close, Right)) ->>> +>>> { stateVisits = 595, stateVisits2 = 876 } List(Split(Space, 0).withPolicy(SingleLineBlock(close)), Split(nl, 1) .withPolicy({ case Decision(t @ FormatToken(_, `close`, _), s) => @@ -154,7 +154,7 @@ Seq( .withIndent(2, lastToken, Left) // case body indented by 2. .withIndent(2, arrow, Left) // cond body indented by 4. ) ->>> +>>> { stateVisits = 703, stateVisits2 = 977 } Seq( // Either everything fits in one line or break on => Split(Space, 0).withPolicy(SingleLineBlock(lastToken)), @@ -273,7 +273,7 @@ class ResolutionCopier(x: Int) { toNode.rightBracket)); } } ->>> +>>> { stateVisits = 57714 } class ResolutionCopier(x: Int) { def visitClassDeclaration(node: ClassDeclaration): Boolean = { @@ -574,7 +574,7 @@ newlines.avoidForSimpleOverflow = [punct] } } }}} ->>> +>>> { stateVisits = 1314, stateVisits2 = 1311 } { { { @@ -1785,7 +1785,7 @@ object a { nme.scala_), scalajs), js), nme.annotation, x, y, z), internal_, a, b, c), wasPublicBeforeTyperXxx) } ->>> +>>> { stateVisits = 1321 } object a { val cls = Select( Select( diff --git a/scalafmt-tests/shared/src/test/resources/default/Idempotency.stat b/scalafmt-tests/shared/src/test/resources/default/Idempotency.stat index 50facefc65..2b7630bda9 100644 --- a/scalafmt-tests/shared/src/test/resources/default/Idempotency.stat +++ b/scalafmt-tests/shared/src/test/resources/default/Idempotency.stat @@ -20,7 +20,7 @@ val bindingFuture = Http().bindAndHandleSync({ upgrade.handleMessages(Flow.fromSinkAndSource(Sink.ignore, Source.fromPublisher(source)), None) }, interface = "localhost", port = 0) }}} ->>> +>>> { stateVisits = 1802, stateVisits2 = 1826 } { { { @@ -58,7 +58,7 @@ val bindingFuture = Http().bindAndHandleSync({ } } } ->>> +>>> { stateVisits = 1826 } { { { @@ -187,7 +187,7 @@ val bindingFuture = Http().bindAndHandleSync({ }) }} ->>> +>>> { stateVisits = 2081, stateVisits2 = 2080 } { { val core = BidiFlow.fromGraph(GraphDSL.create() { implicit b ⇒ diff --git a/scalafmt-tests/shared/src/test/resources/default/Lambda.stat b/scalafmt-tests/shared/src/test/resources/default/Lambda.stat index 4b08ac8f5d..1fa6c65bb0 100644 --- a/scalafmt-tests/shared/src/test/resources/default/Lambda.stat +++ b/scalafmt-tests/shared/src/test/resources/default/Lambda.stat @@ -167,7 +167,7 @@ opt[File]("migrate2hocon") Some(AbsoluteFile.fromFile(file, c.common.workingDirectory)))) .text("""migrate .scalafmt CLI style configuration to hocon style configuration in .scalafmt.conf""") }} ->>> +>>> { stateVisits = 890, stateVisits2 = 889 } { { opt[File]("migrate2hocon") diff --git a/scalafmt-tests/shared/src/test/resources/default/SearchState.stat b/scalafmt-tests/shared/src/test/resources/default/SearchState.stat index 0dec96ead4..5bb57fd030 100644 --- a/scalafmt-tests/shared/src/test/resources/default/SearchState.stat +++ b/scalafmt-tests/shared/src/test/resources/default/SearchState.stat @@ -126,7 +126,7 @@ CLUSTER, sysProp = "spark.jars.ivy") ) } } ->>> +>>> { stateVisits = 1349 } { { val options = List[OptionAssigner]( // All cluster managers @@ -353,7 +353,7 @@ ) ) )) ->>> +>>> { stateVisits = 1096 } EventsResponse.fromJson(json, run).success.value.events should be(Seq( Stored( timestamp = Instant.parse("2016-12-02T16:23:47.412278Z"), @@ -465,7 +465,7 @@ EventsResponse.fromJson(json, run).success.value.events should be(Seq( ^.value := s.text), <.button("Add #", s.items.length + 1))) ).build ->>> +>>> { stateVisits = 972, stateVisits2 = 863 } val TodoApp = ReactComponentB[Unit]("TodoApp") .initialState(State(Nil, "")) .renderS(($, s) => diff --git a/scalafmt-tests/shared/src/test/resources/default/Unindent.stat b/scalafmt-tests/shared/src/test/resources/default/Unindent.stat index 36f755a263..11790a4631 100644 --- a/scalafmt-tests/shared/src/test/resources/default/Unindent.stat +++ b/scalafmt-tests/shared/src/test/resources/default/Unindent.stat @@ -255,7 +255,7 @@ assertEquals(1, case _ => 0 }))) }} ->>> +>>> { stateVisits = 1727, stateVisits2 = 2215 } { { copy(user1 = user1.copy(score = user1.score + (userId match { diff --git a/scalafmt-tests/shared/src/test/resources/newlines/source.source b/scalafmt-tests/shared/src/test/resources/newlines/source.source index f1b227e9b4..7016d3cd25 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source.source +++ b/scalafmt-tests/shared/src/test/resources/newlines/source.source @@ -69,7 +69,7 @@ private[parser] trait CacheControlHeader { this: Parser with CommonRules with Co clearSB() ~ zeroOrMore(!'"' ~ !',' ~ qdtext ~ appendSB() | `quoted-pair`) ~ push(sb.toString) } } ->>> +>>> { stateVisits = 41013 } /** Copyright (C) 2009-2016 Lightbend Inc. */ 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 a422ded05a..e905a7d475 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source_classic.stat +++ b/scalafmt-tests/shared/src/test/resources/newlines/source_classic.stat @@ -3075,7 +3075,7 @@ object a { )) ) } ->>> +>>> { stateVisits = 960, stateVisits2 = 960 } object a { foo( bar.baz( @@ -8894,7 +8894,7 @@ object a { ) ) } ->>> +>>> { stateVisits = 4334, stateVisits2 = 4073 } object a { div(cls := "cover")( div(cls := "doc")(bodyContents), @@ -8997,7 +8997,7 @@ object a { ) ) } ->>> +>>> { stateVisits = 949, stateVisits2 = 605 } object a { div(cls := "cover")( div(cls := "doc")(bodyContents), @@ -9349,7 +9349,7 @@ class UDFRegistration private[sql] (functionRegistry: FunctionRegistry) extends val inputEncoders: Seq[Option[ExpressionEncoder[_]]] = Try(ExpressionEncoder[A1]()).toOption :: Try(ExpressionEncoder[A2]()).toOption :: Try(ExpressionEncoder[A3]()).toOption :: Try(ExpressionEncoder[A4]()).toOption :: Try(ExpressionEncoder[A5]()).toOption :: Try(ExpressionEncoder[A6]()).toOption :: Try(ExpressionEncoder[A7]()).toOption :: Try(ExpressionEncoder[A8]()).toOption :: Try(ExpressionEncoder[A9]()).toOption :: Try(ExpressionEncoder[A10]()).toOption :: Try(ExpressionEncoder[A11]()).toOption :: Try(ExpressionEncoder[A12]()).toOption :: Try(ExpressionEncoder[A13]()).toOption :: Try(ExpressionEncoder[A14]()).toOption :: Try(ExpressionEncoder[A15]()).toOption :: Try(ExpressionEncoder[A16]()).toOption :: Try(ExpressionEncoder[A17]()).toOption :: Try(ExpressionEncoder[A18]()).toOption :: Try(ExpressionEncoder[A19]()).toOption :: Try(ExpressionEncoder[A20]()).toOption :: Try(ExpressionEncoder[A21]()).toOption :: Try(ExpressionEncoder[A22]()).toOption :: Nil } } ->>> +>>> { stateVisits = 2846, stateVisits2 = 1042 } class UDFRegistration private[sql] ( functionRegistry: FunctionRegistry ) extends Logging { @@ -9580,7 +9580,7 @@ class UDFRegistration { val inputEncoders: Seq[Option[ExpressionEncoder[_]]] = Try(ExpressionEncoder[A1]).toOption :: Try(ExpressionEncoder[A2]).toOption :: Try(ExpressionEncoder[A3]).toOption :: Try(ExpressionEncoder[A4]).toOption :: Try(ExpressionEncoder[A5]).toOption :: Try(ExpressionEncoder[A6]).toOption :: Try(ExpressionEncoder[A7]).toOption :: Try(ExpressionEncoder[A8]).toOption :: Try(ExpressionEncoder[A9]).toOption :: Try(ExpressionEncoder[A10]).toOption :: Try(ExpressionEncoder[A11]).toOption :: Try(ExpressionEncoder[A12]).toOption :: Try(ExpressionEncoder[A13]).toOption :: Try(ExpressionEncoder[A14]).toOption :: Try(ExpressionEncoder[A15]).toOption :: Try(ExpressionEncoder[A16]).toOption :: Try(ExpressionEncoder[A17]).toOption :: Try(ExpressionEncoder[A18]).toOption :: Try(ExpressionEncoder[A19]).toOption :: Try(ExpressionEncoder[A20]).toOption :: Try(ExpressionEncoder[A21]).toOption :: Try(ExpressionEncoder[A22]).toOption :: Nil } } ->>> +>>> { stateVisits = 2347, stateVisits2 = 752 } class UDFRegistration { def foo = { val inputEncoders: Seq[ 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 70eb8b197a..b27215f930 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat +++ b/scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat @@ -828,7 +828,7 @@ object a { })(result))))))) }).getMessage should ===("Ur state be b0rked") } ->>> +>>> { stateVisits = 1071 } object a { (intercept[java.lang.IllegalStateException] { wrap(result ⇒ @@ -6778,7 +6778,7 @@ object a { sb.append((if (lsb < 10) ('0' + lsb).asInstanceOf[Char] else ('a' + (lsb - 10)).asInstanceOf[Char])) } ->>> +>>> { stateVisits = 2279 } object a { sb.append((if (msb < 10) ('0' + msb).asInstanceOf[Char] else ('a' + (msb - 10)).asInstanceOf[Char])) @@ -6835,7 +6835,7 @@ object a { } )) } ->>> +>>> { stateVisits = 2057 } object a { buffer.append(( if (!fetchContent) { @@ -6895,7 +6895,7 @@ object a { } )) } ->>> +>>> { stateVisits = 986, stateVisits2 = 986 } object a { buffer .append((if (!fetchContent) { @@ -7465,7 +7465,7 @@ class a { case _ => stepNoBreak(inner)(in) } } ->>> +>>> { stateVisits = 1010 } class a { def step( inner: Iteratee[E, A] @@ -8356,7 +8356,7 @@ object a { ) ) } ->>> +>>> { stateVisits = 78932 } object a { div(cls := "cover")( div(cls := "doc")(bodyContents), @@ -8441,7 +8441,7 @@ object a { ) ) } ->>> +>>> { stateVisits = 36381 } object a { div(cls := "cover")( div(cls := "doc")(bodyContents), @@ -8774,7 +8774,7 @@ class UDFRegistration private[sql] (functionRegistry: FunctionRegistry) extends val inputEncoders: Seq[Option[ExpressionEncoder[_]]] = Try(ExpressionEncoder[A1]()).toOption :: Try(ExpressionEncoder[A2]()).toOption :: Try(ExpressionEncoder[A3]()).toOption :: Try(ExpressionEncoder[A4]()).toOption :: Try(ExpressionEncoder[A5]()).toOption :: Try(ExpressionEncoder[A6]()).toOption :: Try(ExpressionEncoder[A7]()).toOption :: Try(ExpressionEncoder[A8]()).toOption :: Try(ExpressionEncoder[A9]()).toOption :: Try(ExpressionEncoder[A10]()).toOption :: Try(ExpressionEncoder[A11]()).toOption :: Try(ExpressionEncoder[A12]()).toOption :: Try(ExpressionEncoder[A13]()).toOption :: Try(ExpressionEncoder[A14]()).toOption :: Try(ExpressionEncoder[A15]()).toOption :: Try(ExpressionEncoder[A16]()).toOption :: Try(ExpressionEncoder[A17]()).toOption :: Try(ExpressionEncoder[A18]()).toOption :: Try(ExpressionEncoder[A19]()).toOption :: Try(ExpressionEncoder[A20]()).toOption :: Try(ExpressionEncoder[A21]()).toOption :: Try(ExpressionEncoder[A22]()).toOption :: Nil } } ->>> +>>> { stateVisits = 807, stateVisits2 = 807 } class UDFRegistration private[sql] ( functionRegistry: FunctionRegistry ) extends Logging { @@ -9201,7 +9201,7 @@ object Build { }.evaluated, ) } ->>> +>>> { stateVisits = 1607 } object Build { lazy val scaladoc = project.in(file("scaladoc")) .settings(generateScalaDocumentation := Def.inputTaskDyn { 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 63a809b573..a50c454ebd 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source_unfold.stat +++ b/scalafmt-tests/shared/src/test/resources/newlines/source_unfold.stat @@ -8975,7 +8975,7 @@ object a { ) ) } ->>> +>>> { stateVisits = 2540 } object a { div(cls := "cover")( div(cls := "doc")(bodyContents), @@ -9076,7 +9076,7 @@ object a { ) ) } ->>> +>>> { stateVisits = 2346 } object a { div(cls := "cover")( div(cls := "doc")(bodyContents), @@ -9448,7 +9448,7 @@ class UDFRegistration private[sql] (functionRegistry: FunctionRegistry) extends val inputEncoders: Seq[Option[ExpressionEncoder[_]]] = Try(ExpressionEncoder[A1]()).toOption :: Try(ExpressionEncoder[A2]()).toOption :: Try(ExpressionEncoder[A3]()).toOption :: Try(ExpressionEncoder[A4]()).toOption :: Try(ExpressionEncoder[A5]()).toOption :: Try(ExpressionEncoder[A6]()).toOption :: Try(ExpressionEncoder[A7]()).toOption :: Try(ExpressionEncoder[A8]()).toOption :: Try(ExpressionEncoder[A9]()).toOption :: Try(ExpressionEncoder[A10]()).toOption :: Try(ExpressionEncoder[A11]()).toOption :: Try(ExpressionEncoder[A12]()).toOption :: Try(ExpressionEncoder[A13]()).toOption :: Try(ExpressionEncoder[A14]()).toOption :: Try(ExpressionEncoder[A15]()).toOption :: Try(ExpressionEncoder[A16]()).toOption :: Try(ExpressionEncoder[A17]()).toOption :: Try(ExpressionEncoder[A18]()).toOption :: Try(ExpressionEncoder[A19]()).toOption :: Try(ExpressionEncoder[A20]()).toOption :: Try(ExpressionEncoder[A21]()).toOption :: Try(ExpressionEncoder[A22]()).toOption :: Nil } } ->>> +>>> { stateVisits = 803, stateVisits2 = 803 } class UDFRegistration private[sql] ( functionRegistry: FunctionRegistry ) extends Logging { diff --git a/scalafmt-tests/shared/src/test/resources/rewrite/RedundantParens.stat b/scalafmt-tests/shared/src/test/resources/rewrite/RedundantParens.stat index 62c05790a0..eee48be377 100644 --- a/scalafmt-tests/shared/src/test/resources/rewrite/RedundantParens.stat +++ b/scalafmt-tests/shared/src/test/resources/rewrite/RedundantParens.stat @@ -672,7 +672,7 @@ object Application { def main(args: Array[String]): Unit = app.run(args) } ->>> +>>> { stateVisits = 854, stateVisits2 = 854 } object Application { val app = reactiveWebApplication(a => a.beans(b => b.bean(classOf[SampleHandler]).bean(classOf[SampleService])) @@ -733,7 +733,7 @@ object Application { def main(args: Array[String]): Unit = app.run(args) } ->>> +>>> { stateVisits = 854, stateVisits2 = 854 } object Application { val app = reactiveWebApplication(a => a.beans(b => b.bean(classOf[SampleHandler]).bean(classOf[SampleService])) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat index 5f9547d74d..189ffc39dd 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat @@ -5148,7 +5148,7 @@ class test: <<< overflowing type object types: type GOutputStreamClass = CStruct21[GObjectClass, CFuncPtr5[Ptr[GOutputStream], Ptr[Byte], gsize, Ptr[GCancellable], Ptr[Ptr[GError]], gssize], CFuncPtr5[Ptr[GOutputStream], Ptr[GInputStream], GOutputStreamSpliceFlags, Ptr[GCancellable], Ptr[Ptr[GError]], gssize], CFuncPtr3[Ptr[GOutputStream], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr3[Ptr[GOutputStream], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr7[Ptr[GOutputStream], Ptr[Byte], gsize, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gssize], CFuncPtr7[Ptr[GOutputStream], Ptr[GInputStream], GOutputStreamSpliceFlags, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gssize], CFuncPtr5[Ptr[GOutputStream], CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gboolean], CFuncPtr5[Ptr[GOutputStream], CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gboolean], CFuncPtr6[Ptr[GOutputStream], Ptr[GOutputVector], gsize, Ptr[gsize], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr7[Ptr[GOutputStream], Ptr[GOutputVector], gsize, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr4[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[gsize], Ptr[Ptr[GError]], gboolean], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit]] ->>> +>>> { stateVisits = 837, stateVisits2 = 630 } object types: type GOutputStreamClass = CStruct21[ GObjectClass, @@ -6987,7 +6987,7 @@ object a { g.asInstanceOf[Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Any].apply((x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18))).asInstanceOf[F] ) } ->>> +>>> { stateVisits = 2408, stateVisits2 = 2864 } object a { def tupledFunction18[F, G]: TupledFunction[F, G] = TupledFunction[F, G]( untupledImpl = (g: G) => 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 92bd396e07..3c28041a96 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat @@ -1005,7 +1005,7 @@ object Foo: case a: A if a.someField.otherField.function().exists(SomeObjectLongName.isTrue) => None ) ->>> +>>> { stateVisits = 1020, stateVisits2 = 1024 } object Foo: def bar = process( arg match @@ -4899,7 +4899,7 @@ class test: <<< overflowing type object types: type GOutputStreamClass = CStruct21[GObjectClass, CFuncPtr5[Ptr[GOutputStream], Ptr[Byte], gsize, Ptr[GCancellable], Ptr[Ptr[GError]], gssize], CFuncPtr5[Ptr[GOutputStream], Ptr[GInputStream], GOutputStreamSpliceFlags, Ptr[GCancellable], Ptr[Ptr[GError]], gssize], CFuncPtr3[Ptr[GOutputStream], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr3[Ptr[GOutputStream], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr7[Ptr[GOutputStream], Ptr[Byte], gsize, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gssize], CFuncPtr7[Ptr[GOutputStream], Ptr[GInputStream], GOutputStreamSpliceFlags, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gssize], CFuncPtr5[Ptr[GOutputStream], CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gboolean], CFuncPtr5[Ptr[GOutputStream], CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gboolean], CFuncPtr6[Ptr[GOutputStream], Ptr[GOutputVector], gsize, Ptr[gsize], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr7[Ptr[GOutputStream], Ptr[GOutputVector], gsize, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr4[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[gsize], Ptr[Ptr[GError]], gboolean], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit]] ->>> +>>> { stateVisits = 835, stateVisits2 = 835 } object types: type GOutputStreamClass = CStruct21[ GObjectClass, @@ -5927,7 +5927,7 @@ object a: }) index } ->>> +>>> { stateVisits = 1569 } object a: private val packageIndex : scala.collection.Map[String, scala.collection.Seq[Path]] = { @@ -6697,7 +6697,7 @@ object a { g.asInstanceOf[Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Any].apply((x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18))).asInstanceOf[F] ) } ->>> +>>> { stateVisits = 3402 } object a { def tupledFunction18[F, G]: TupledFunction[F, G] = TupledFunction[F, G]( untupledImpl = (g: G) => 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 51e2359c98..d1d6335486 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat @@ -7024,7 +7024,7 @@ object a { g.asInstanceOf[Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Any].apply((x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18))).asInstanceOf[F] ) } ->>> +>>> { stateVisits = 1295, stateVisits2 = 1274 } object a { def tupledFunction18[F, G]: TupledFunction[F, G] = TupledFunction[F, G]( untupledImpl = (g: G) => 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 67861cc01d..5f9287f1a0 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -5306,7 +5306,7 @@ class test: <<< overflowing type object types: type GOutputStreamClass = CStruct21[GObjectClass, CFuncPtr5[Ptr[GOutputStream], Ptr[Byte], gsize, Ptr[GCancellable], Ptr[Ptr[GError]], gssize], CFuncPtr5[Ptr[GOutputStream], Ptr[GInputStream], GOutputStreamSpliceFlags, Ptr[GCancellable], Ptr[Ptr[GError]], gssize], CFuncPtr3[Ptr[GOutputStream], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr3[Ptr[GOutputStream], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr7[Ptr[GOutputStream], Ptr[Byte], gsize, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gssize], CFuncPtr7[Ptr[GOutputStream], Ptr[GInputStream], GOutputStreamSpliceFlags, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gssize], CFuncPtr5[Ptr[GOutputStream], CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gboolean], CFuncPtr5[Ptr[GOutputStream], CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr3[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[Ptr[GError]], gboolean], CFuncPtr6[Ptr[GOutputStream], Ptr[GOutputVector], gsize, Ptr[gsize], Ptr[GCancellable], Ptr[Ptr[GError]], gboolean], CFuncPtr7[Ptr[GOutputStream], Ptr[GOutputVector], gsize, CInt, Ptr[GCancellable], GAsyncReadyCallback, gpointer, Unit], CFuncPtr4[Ptr[GOutputStream], Ptr[GAsyncResult], Ptr[gsize], Ptr[Ptr[GError]], gboolean], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit], CFuncPtr0[Unit]] ->>> +>>> { stateVisits = 834, stateVisits2 = 834 } object types: type GOutputStreamClass = CStruct21[ GObjectClass, @@ -7244,7 +7244,7 @@ object a { g.asInstanceOf[Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Any].apply((x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18))).asInstanceOf[F] ) } ->>> +>>> { stateVisits = 941, stateVisits2 = 941 } object a { def tupledFunction18[F, G]: TupledFunction[F, G] = TupledFunction[F, G]( untupledImpl = diff --git a/scalafmt-tests/shared/src/test/resources/scalajs/Apply.stat b/scalafmt-tests/shared/src/test/resources/scalajs/Apply.stat index a27ae548f4..babe067843 100644 --- a/scalafmt-tests/shared/src/test/resources/scalajs/Apply.stat +++ b/scalafmt-tests/shared/src/test/resources/scalajs/Apply.stat @@ -600,7 +600,7 @@ optDef.getOrElse { bar, foo && bar, baz) ) } ->>> +>>> { stateVisits = 2153, stateVisits2 = 2105 } optDef.getOrElse { abort(foo && bar) diff --git a/scalafmt-tests/shared/src/test/resources/scalajs/DefDef.stat b/scalafmt-tests/shared/src/test/resources/scalajs/DefDef.stat index 474fedce11..7edd9b7946 100644 --- a/scalafmt-tests/shared/src/test/resources/scalajs/DefDef.stat +++ b/scalafmt-tests/shared/src/test/resources/scalajs/DefDef.stat @@ -682,7 +682,7 @@ trait EntityPage extends HtmlPage { ) } ->>> +>>> { stateVisits = 1042, stateVisits2 = 379 } trait EntityPage extends HtmlPage { def search = Div( @@ -787,7 +787,7 @@ val memberSel: Elems = )) ) )) ->>> +>>> { stateVisits = 1960, stateVisits2 = 1454 } val memberSel: Elems = if (valueMembers.forall(_.kind == "package")) NoElems else List( diff --git a/scalafmt-tests/shared/src/test/resources/unit/TermApply.stat b/scalafmt-tests/shared/src/test/resources/unit/TermApply.stat index c0e894c852..f4f01bbcb2 100644 --- a/scalafmt-tests/shared/src/test/resources/unit/TermApply.stat +++ b/scalafmt-tests/shared/src/test/resources/unit/TermApply.stat @@ -44,7 +44,7 @@ var list = List( // comment <<< long var list = List( function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C), function(a: A, b: B, c: C) ); ->>> +>>> { stateVisits = 930, stateVisits2 = 930 } var list = List( function(a: A, b: B, c: C), function(a: A, b: B, c: C), 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 7dc1090961..9e1715ed75 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -71,7 +71,10 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions { case Some(visits1) => val expected = (visits1, visitsOpt2.getOrElse(visits1)) assertEquals(actual, expected, error) - case None => + case None => assert( + actual1 <= 800 && actual2 <= 800, + s"\nExpected test to assert: $error", + ) } } var debug2Opt: Option[Debug] = None