Skip to content

Commit

Permalink
Add tests with opt-braces rewrite and if-cond
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jul 6, 2023
1 parent 5b11cf6 commit 4d79989
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
35 changes: 35 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,41 @@ object a:
stat4
end if
end cond
<<< remove optional braces within if-cond
rewrite.scala3.removeOptionalBraces = yes
===
private def mtd: Res =
if {
bar &&
baz
} then
foo
>>>
Idempotency violated
private def mtd: Res =
- if bar &&
+ if
+ bar &&
baz
then foo
<<< remove optional braces within else-if
rewrite.scala3.removeOptionalBraces = yes
===
private def mtd: Res =
if foo then fooBody
else {
if bar then
barBody
else bazBody
}
>>>
Idempotency violated
if foo then fooBody
- else if bar then barBody
- else bazBody
+ else
+ if bar then barBody
+ else bazBody
<<< rewrite with given-with
rewrite.scala3.removeOptionalBraces = oldSyntaxToo
===
Expand Down
28 changes: 28 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,34 @@ object a:
stat4
end if
end cond
<<< remove optional braces within if-cond
rewrite.scala3.removeOptionalBraces = yes
===
private def mtd: Res =
if {
bar &&
baz
} then
foo
>>>
Idempotency violated
-private def mtd: Res = if bar && baz then foo
+private def mtd: Res =
+ if
+ bar && baz
+ then foo
<<< remove optional braces within else-if
rewrite.scala3.removeOptionalBraces = yes
===
private def mtd: Res =
if foo then fooBody
else {
if bar then
barBody
else bazBody
}
>>>
private def mtd: Res = if foo then fooBody else if bar then barBody else bazBody
<<< rewrite with given-with
rewrite.scala3.removeOptionalBraces = oldSyntaxToo
===
Expand Down
37 changes: 37 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,43 @@ object a:
stat4
end if
end cond
<<< remove optional braces within if-cond
rewrite.scala3.removeOptionalBraces = yes
===
private def mtd: Res =
if {
bar &&
baz
} then
foo
>>>
private def mtd: Res =
if
bar &&
baz
then
foo
<<< remove optional braces within else-if
rewrite.scala3.removeOptionalBraces = yes
===
private def mtd: Res =
if foo then fooBody
else {
if bar then
barBody
else bazBody
}
>>>
Idempotency violated
private def mtd: Res =
if foo then fooBody
- else if bar then
- barBody
- else bazBody
+ else
+ if bar then
+ barBody
+ else bazBody
<<< rewrite with given-with
rewrite.scala3.removeOptionalBraces = oldSyntaxToo
===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,47 @@ object a:
stat4
end if
end cond
<<< remove optional braces within if-cond
rewrite.scala3.removeOptionalBraces = yes
===
private def mtd: Res =
if {
bar &&
baz
} then
foo
>>>
Idempotency violated
private def mtd: Res =
- if bar && baz then
+ if
+ bar && baz
+ then
baz
then foo
<<< remove optional braces within else-if
rewrite.scala3.removeOptionalBraces = yes
===
private def mtd: Res =
if foo then fooBody
else {
if bar then
barBody
else bazBody
}
>>>
Idempotency violated
private def mtd: Res =
if foo then
fooBody
- else if bar then
- barBody
else
- bazBody
+ if bar then
+ barBody
+ else
+ bazBody
<<< rewrite with given-with
rewrite.scala3.removeOptionalBraces = oldSyntaxToo
===
Expand Down

0 comments on commit 4d79989

Please sign in to comment.