From c27b71ef95deb09629d427c8328b52fa698db4e9 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:56:33 -0700 Subject: [PATCH] Add tests with break/paren/comment --- .../src/test/resources/default/Apply.stat | 60 +++++++++++++++++++ .../test/resources/default/Idempotency.stat | 38 ++++++++++++ .../src/test/resources/default/Select.stat | 50 ++++++++++++++++ .../test/resources/optIn/SelectChains.stat | 30 ++++++++++ .../src/test/resources/unit/Apply.stat | 20 +++++++ .../src/test/resources/unit/Lambda.stat | 18 ++++++ 6 files changed, 216 insertions(+) diff --git a/scalafmt-tests/src/test/resources/default/Apply.stat b/scalafmt-tests/src/test/resources/default/Apply.stat index 5b01202f77..3fc79c55bb 100644 --- a/scalafmt-tests/src/test/resources/default/Apply.stat +++ b/scalafmt-tests/src/test/resources/default/Apply.stat @@ -652,6 +652,24 @@ SSLConfig(SSLLooseConfig(allowLegacyHelloMessages = None)/*comment 123 comment 2 ) ) // comment 345 comment 456 } +<<< #1604 1: apply with then without assign, and attached comments, with breaks before paren/comment +{ + val config = WSClientConfig(ssl = + SSLConfig( + SSLLooseConfig(allowLegacyHelloMessages = + None) /*comment 123 comment 234*/ + ) + ) // comment 345 comment 456 +} +>>> +{ + val config = WSClientConfig(ssl = + SSLConfig( + SSLLooseConfig(allowLegacyHelloMessages = + None) /*comment 123 comment 234*/ + ) + ) // comment 345 comment 456 +} <<< #1604 2: apply without then with assign, and attached comments { val config = WSClientConfig( @@ -666,6 +684,24 @@ SSLConfig(loose = SSLLooseConfig(allowLegacyHelloMessages = None)/*comment 123 c ) ) // comment 345 comment 456 } +<<< #1604 2: apply without then with assign, and attached comments, with breaks before paren/comment +{ + val config = WSClientConfig( + SSLConfig(loose = + SSLLooseConfig(allowLegacyHelloMessages = + None) /*comment 123 comment 234*/ + ) + ) // comment 345 comment 456 +} +>>> +{ + val config = WSClientConfig( + SSLConfig(loose = + SSLLooseConfig(allowLegacyHelloMessages = + None) /*comment 123 comment 234*/ + ) + ) // comment 345 comment 456 +} <<< #1604 3: apply with assign and attached comments { val config = WSClientConfig(ssl = @@ -677,6 +713,18 @@ SSLConfig(loose = SSLLooseConfig(allowLegacyHelloMessages = None)/*comment 123 c SSLLooseConfig(allowLegacyHelloMessages = None) /*comment 123 comment 234*/ )) // comment 345 comment 456 } +<<< #1604 3: apply with assign and attached comments, with breaks before paren/comment +{ + val config = WSClientConfig(ssl = SSLConfig(loose = + SSLLooseConfig(allowLegacyHelloMessages = None) /*comment 123 comment 234*/ + )) // comment 345 comment 456 +} +>>> +{ + val config = WSClientConfig(ssl = SSLConfig(loose = + SSLLooseConfig(allowLegacyHelloMessages = None) /*comment 123 comment 234*/ + )) // comment 345 comment 456 +} <<< #1604 4: apply without assign and attached comments { val config = WSClientConfig( @@ -688,6 +736,18 @@ SSLConfig(SSLLooseConfig(None)/*comment 123 comment 234*/)) //comment 345 commen SSLConfig(SSLLooseConfig(None) /*comment 123 comment 234*/ ) ) // comment 345 comment 456 } +<<< #1604 4: apply without assign and attached comments, with breaks before paren/comment +{ + val config = WSClientConfig( + SSLConfig(SSLLooseConfig(None) /*comment 123 comment 234*/ ) + ) // comment 345 comment 456 +} +>>> +{ + val config = WSClientConfig( + SSLConfig(SSLLooseConfig(None) /*comment 123 comment 234*/ ) + ) // comment 345 comment 456 +} <<< comment in first arg, no newline maxColumn = 28 === diff --git a/scalafmt-tests/src/test/resources/default/Idempotency.stat b/scalafmt-tests/src/test/resources/default/Idempotency.stat index 9218d32a2e..4f39ee30c0 100644 --- a/scalafmt-tests/src/test/resources/default/Idempotency.stat +++ b/scalafmt-tests/src/test/resources/default/Idempotency.stat @@ -39,6 +39,44 @@ val bindingFuture = Http().bindAndHandleSync({ } } } +<<< akka 1, expanded +{ + { + { + val bindingFuture = Http().bindAndHandleSync( + { case HttpRequest(_, _, headers, _, _) ⇒ + val upgrade = headers.collectFirst { case u: UpgradeToWebSocket ⇒ + u + }.get + upgrade.handleMessages( + Flow.fromSinkAndSource(Sink.ignore, + Source.fromPublisher(source)), + None) + }, + interface = "localhost", + port = 0) + } + } +} +>>> +{ + { + { + val bindingFuture = Http().bindAndHandleSync( + { case HttpRequest(_, _, headers, _, _) ⇒ + val upgrade = headers.collectFirst { case u: UpgradeToWebSocket ⇒ + u + }.get + upgrade.handleMessages( + Flow.fromSinkAndSource(Sink.ignore, + Source.fromPublisher(source)), + None) + }, + interface = "localhost", + port = 0) + } + } +} <<< raw-request idempotent {{{{{{ RawRequestURI(new String(uriBytes, HttpCharsets.aaaaaaaaaa.nioCharset)) :: headers diff --git a/scalafmt-tests/src/test/resources/default/Select.stat b/scalafmt-tests/src/test/resources/default/Select.stat index e5d44ef773..b8a0fbce6d 100644 --- a/scalafmt-tests/src/test/resources/default/Select.stat +++ b/scalafmt-tests/src/test/resources/default/Select.stat @@ -107,6 +107,30 @@ private def extractRhino(e: js.Dynamic): js.Array[String] = { ) // Rhino has platform-dependent EOL's .jsSplit("\n") } +<<< rhino superfluous parenthesis, with breaks before paren/comment +private def extractRhino(e: js.Dynamic): js.Array[String] = { + (e.stack + .asInstanceOf[js.UndefOr[String]]) + .getOrElse("") + .jsReplace("""^\s+at\s+""".re("gm"), "") // remove 'at' and indentation + .jsReplace("""^(.+?)(?: \((.+)\))?$""".re("gm"), "$2@$1") + .jsReplace("""\r\n?""".re("gm"), + "\n" + ) // Rhino has platform-dependent EOL's + .jsSplit("\n") +} +>>> +private def extractRhino(e: js.Dynamic): js.Array[String] = { + (e.stack + .asInstanceOf[js.UndefOr[String]]) + .getOrElse("") + .jsReplace("""^\s+at\s+""".re("gm"), "") // remove 'at' and indentation + .jsReplace("""^(.+?)(?: \((.+)\))?$""".re("gm"), "$2@$1") + .jsReplace("""\r\n?""".re("gm"), + "\n" + ) // Rhino has platform-dependent EOL's + .jsSplit("\n") +} <<< rhino superfluous parenthesis, align close align.closeParenSite = true === @@ -129,6 +153,32 @@ private def extractRhino(e: js.Dynamic): js.Array[String] = { ) // Rhino has platform-dependent EOL's .jsSplit("\n") } +<<< rhino superfluous parenthesis, align close, with breaks before paren/comment +align.closeParenSite = true +=== +private def extractRhino(e: js.Dynamic): js.Array[String] = { + (e.stack + .asInstanceOf[js.UndefOr[String]]) + .getOrElse("") + .jsReplace("""^\s+at\s+""".re("gm"), "") // remove 'at' and indentation + .jsReplace("""^(.+?)(?: \((.+)\))?$""".re("gm"), "$2@$1") + .jsReplace("""\r\n?""".re("gm"), + "\n" + ) // Rhino has platform-dependent EOL's + .jsSplit("\n") +} +>>> +private def extractRhino(e: js.Dynamic): js.Array[String] = { + (e.stack + .asInstanceOf[js.UndefOr[String]]) + .getOrElse("") + .jsReplace("""^\s+at\s+""".re("gm"), "") // remove 'at' and indentation + .jsReplace("""^(.+?)(?: \((.+)\))?$""".re("gm"), "$2@$1") + .jsReplace("""\r\n?""".re("gm"), + "\n" + ) // Rhino has platform-dependent EOL's + .jsSplit("\n") +} <<< select is cheaper new ReflectiveDynamicAccess(classLoader).createInstanceFor[ScalaFmtLike]( "org.scalafmt.ScalaFmt210", Seq.empty) diff --git a/scalafmt-tests/src/test/resources/optIn/SelectChains.stat b/scalafmt-tests/src/test/resources/optIn/SelectChains.stat index e813c2d776..3c4c62a2d4 100644 --- a/scalafmt-tests/src/test/resources/optIn/SelectChains.stat +++ b/scalafmt-tests/src/test/resources/optIn/SelectChains.stat @@ -27,3 +27,33 @@ val design: Design = .bind[D3].toInstance(D3(3)) // Bind D3 to a concrete instance D3(3) .bind[D3].toInstance(D3(3)).bind[D3].toInstance(D3(3)).bind[D3].toInstance( D3(3)).bind[D3].toInstance(D3(3)).bind[D3].toInstance(D3(3)) +<<< airframe, with breaks before paren/comment +val design: Design = + newDesign // Create an empty design + .bind[A].to[AImpl] // Bind a concrete class AImpl to A + .bind[B].toInstance( + new B(1) + ) // Bind a concrete instance to B (This instance will be a singleton) + .bind[S].toSingleton // S will be a singleton within the session + .bind[ES].toEagerSingleton // ES will be initialized as a singleton at session start time + .bind[D1] + .toInstance(D1(1)) // Bind D1 to a concrete instance D1(1) + .bind[D2].toInstance(D2(2)) // Bind D2 to a concrete instance D2(2) + .bind[D3].toInstance(D3(3)) // Bind D3 to a concrete instance D3(3) + .bind[D3].toInstance(D3(3)).bind[D3].toInstance(D3(3)).bind[D3].toInstance( + D3(3)).bind[D3].toInstance(D3(3)).bind[D3].toInstance(D3(3)) +>>> +val design: Design = + newDesign // Create an empty design + .bind[A].to[AImpl] // Bind a concrete class AImpl to A + .bind[B].toInstance( + new B(1) + ) // Bind a concrete instance to B (This instance will be a singleton) + .bind[S].toSingleton // S will be a singleton within the session + .bind[ES].toEagerSingleton // ES will be initialized as a singleton at session start time + .bind[D1] + .toInstance(D1(1)) // Bind D1 to a concrete instance D1(1) + .bind[D2].toInstance(D2(2)) // Bind D2 to a concrete instance D2(2) + .bind[D3].toInstance(D3(3)) // Bind D3 to a concrete instance D3(3) + .bind[D3].toInstance(D3(3)).bind[D3].toInstance(D3(3)).bind[D3].toInstance( + D3(3)).bind[D3].toInstance(D3(3)).bind[D3].toInstance(D3(3)) diff --git a/scalafmt-tests/src/test/resources/unit/Apply.stat b/scalafmt-tests/src/test/resources/unit/Apply.stat index 01d5703d1e..23e02fdb58 100644 --- a/scalafmt-tests/src/test/resources/unit/Apply.stat +++ b/scalafmt-tests/src/test/resources/unit/Apply.stat @@ -23,6 +23,26 @@ new DenseMatrix( majorStride = from.majorStride, isTranspose = !from.isTranspose) >>> +new DenseMatrix( + data = from.data map { + _.conjugate + }, + offset = from.offset, + cols = from.rows, + rows = from.cols, + majorStride = from.majorStride, + isTranspose = !from.isTranspose) +<<< Init, multiline map +new DenseMatrix( + data = from.data map { + _.conjugate + }, + offset = from.offset, + cols = from.rows, + rows = from.cols, + majorStride = from.majorStride, + isTranspose = !from.isTranspose) +>>> new DenseMatrix( data = from.data map { _.conjugate diff --git a/scalafmt-tests/src/test/resources/unit/Lambda.stat b/scalafmt-tests/src/test/resources/unit/Lambda.stat index 9239dab938..944a027e5d 100644 --- a/scalafmt-tests/src/test/resources/unit/Lambda.stat +++ b/scalafmt-tests/src/test/resources/unit/Lambda.stat @@ -89,6 +89,24 @@ Thing(implicit ctx => j => ???) <<< long curried with () Thing(implicit ctx => j => k => aaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbb, cccccccccc, ddddddddddddddddddddj)) // coooooooooooooooomment >>> +Thing(implicit ctx => + j => + k => + aaaaaaaaaaaaa( + bbbbbbbbbbbbbbbbbbb, + cccccccccc, + ddddddddddddddddddddj + )) // coooooooooooooooomment +<<< long curried with (), with breaks before paren/comment +Thing(implicit ctx => + j => + k => + aaaaaaaaaaaaa( + bbbbbbbbbbbbbbbbbbb, + cccccccccc, + ddddddddddddddddddddj + )) // coooooooooooooooomment +>>> Thing(implicit ctx => j => k =>