Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splits: handle do-while conditions as well #4867

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2003,12 +2003,10 @@ object SplitsAfterLeftParen extends Splits {
else alignIndents,
))
}
def withCond(t: Tree.WithCond) =
if (isTokenHeadOrBefore(left, t)) None else impl(isEnclosedInBraces(t.cond))
leftOwner match { // If/For/While/For with (
case t: Term.EnumeratorsBlock if getHeadOpt(t).contains(ft) => impl(false)
case t: Term.If => withCond(t)
case t: Term.While => withCond(t)
case t: Tree.WithCond if !isTokenHeadOrBefore(left, t) =>
impl(isEnclosedInBraces(t.cond))
case _ => None
}
}
Expand Down
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(59399907)
override protected def totalStatesVisited: Option[Int] = Some(59404572)

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

override protected def totalStatesVisited: Option[Int] = Some(59614646)
override protected def totalStatesVisited: Option[Int] = Some(59619311)

override protected def builds = Seq {
getBuild(
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(42553260)
override protected def totalStatesVisited: Option[Int] = Some(42553676)

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(53018051)
override protected def totalStatesVisited: Option[Int] = Some(53018427)

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,15 +9,15 @@ abstract class CommunitySparkSuite(name: String)

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

override protected def totalStatesVisited: Option[Int] = Some(85964934)
override protected def totalStatesVisited: Option[Int] = Some(85967060)

override protected def builds = Seq(getBuild("v3.4.1", dialects.Scala213, 2585))

}

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

override protected def totalStatesVisited: Option[Int] = Some(90969442)
override protected def totalStatesVisited: Option[Int] = Some(90971586)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12081,7 +12081,55 @@ object a {
|baz
|qux""".stripMargin
}
<<< `do` starts a new statement
<<< `do` starts a new statement, narrow, danglingParentheses.ctrlSite
danglingParentheses.ctrlSite = true
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (
ch != CR && ch != LF && ch != FF && ch != SU
)
}
<<< `do` starts a new statement, wide, danglingParentheses.ctrlSite
maxColumn = 60
danglingParentheses.ctrlSite = true
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
<<< `do` starts a new statement, narrow, !danglingParentheses.ctrlSite
danglingParentheses.ctrlSite = false
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
<<< `do` starts a new statement, wide, !danglingParentheses.ctrlSite
maxColumn = 60
danglingParentheses.ctrlSite = false
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
Expand Down
56 changes: 53 additions & 3 deletions scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -11308,7 +11308,57 @@ object a {
|baz
|qux""".stripMargin
}
<<< `do` starts a new statement
<<< `do` starts a new statement, narrow, danglingParentheses.ctrlSite
danglingParentheses.ctrlSite = true
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext() while (
ch != CR && ch != LF && ch != FF &&
ch != SU
)
}
<<< `do` starts a new statement, wide, danglingParentheses.ctrlSite
maxColumn = 60
danglingParentheses.ctrlSite = true
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext() while (
ch != CR && ch != LF && ch != FF && ch != SU
)
}
<<< `do` starts a new statement, narrow, !danglingParentheses.ctrlSite
danglingParentheses.ctrlSite = false
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF &&
ch != FF && ch != SU)
}
<<< `do` starts a new statement, wide, !danglingParentheses.ctrlSite
maxColumn = 60
danglingParentheses.ctrlSite = false
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
Expand All @@ -11317,8 +11367,8 @@ def foo = {
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext() while (ch != CR &&
ch != LF && ch != FF && ch != SU)
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
<<< splits: `after equals` or `before statement` 1
maxColumn = 80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11853,7 +11853,55 @@ object a {
|baz
|qux""".stripMargin
}
<<< `do` starts a new statement
<<< `do` starts a new statement, narrow, danglingParentheses.ctrlSite
danglingParentheses.ctrlSite = true
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (
ch != CR && ch != LF && ch != FF && ch != SU
)
}
<<< `do` starts a new statement, wide, danglingParentheses.ctrlSite
maxColumn = 60
danglingParentheses.ctrlSite = true
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
<<< `do` starts a new statement, narrow, !danglingParentheses.ctrlSite
danglingParentheses.ctrlSite = false
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
<<< `do` starts a new statement, wide, !danglingParentheses.ctrlSite
maxColumn = 60
danglingParentheses.ctrlSite = false
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12322,7 +12322,9 @@ object a {
|baz
|qux""".stripMargin
}
<<< `do` starts a new statement
<<< `do` starts a new statement, narrow, danglingParentheses.ctrlSite
danglingParentheses.ctrlSite = true
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
Expand All @@ -12336,6 +12338,52 @@ def foo = {
ch != SU
)
}
<<< `do` starts a new statement, wide, danglingParentheses.ctrlSite
maxColumn = 60
danglingParentheses.ctrlSite = true
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext() while (
ch != CR && ch != LF && ch != FF && ch != SU
)
}
<<< `do` starts a new statement, narrow, !danglingParentheses.ctrlSite
danglingParentheses.ctrlSite = false
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF &&
ch != FF && ch != SU)
}
<<< `do` starts a new statement, wide, !danglingParentheses.ctrlSite
maxColumn = 60
danglingParentheses.ctrlSite = false
===
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
>>>
def foo = {
next.offset = begCharOffset
do putCharAndNext()
while (ch != CR && ch != LF && ch != FF && ch != SU)
}
<<< splits: `after equals` or `before statement` 1
maxColumn = 80
===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2480,9 +2480,15 @@ object a {
>>>
object a {
do foo
while (true)
while (
true
)
do a + b
while (true)
while (
true
)
do a + b
while (true)
while (
true
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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, 2549280, "total explored")
assertEquals(explored, 2552242, "total explored")
// TODO(olafur) don't block printing out test results.
TestPlatformCompat.executeAndWait(PlatformFileOps.writeFile(
FileOps.getPath("target", "index.html"),
Expand Down