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

Add test examples for non-ideal situations #488

Closed
wants to merge 6 commits into from
Closed
Changes from 2 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 @@ -587,6 +587,116 @@ class GoogleStyleFormatterKtTest {
.trimMargin(),
)

@Test
fun `Trailing comma forces variable value in list onto new line with manageTrailingCommas turned off`() =
hick209 marked this conversation as resolved.
Show resolved Hide resolved
assertFormatted(
"""
val aVar =
setOf(
Env.Dev,
Env.Prod,
)
val aVar = setOf(Env.Dev, Env.Prod)

""".trimIndent(),
formattingOptions = FormattingOptions(
blockIndent = 4,
continuationIndent = 4,
manageTrailingCommas = false
),
deduceMaxWidth = false,
)

@Test
fun `nested functions, maps, and statements in named parameters`() =
hick209 marked this conversation as resolved.
Show resolved Hide resolved
assertFormatted(
"""
/////////////////////////////////////////////////////////////////////
function(
param =
(rate downTo min step step).drop(1).map {
nestedFun(
rate =
rate(
value =
firstArg<Input>().info.get(0).rate.value
)
)
}
)

""".trimIndent(),
formattingOptions = Formatter.KOTLINLANG_FORMAT,
deduceMaxWidth = true,
)

@Test
fun `complex calls and calculation in named parameters with wrapping`() =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to FormatterTest.kt, omit formattingOptions if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so omitting the formatting options here showed another weird bug between google/kotlin formats. I moved it to FormatterTest and added another test to show the difference.

assertFormatted(
"""
////////////////////////////////////////////////////
calculateMath(
r =
apr.sc(10) /
BigDecimal(100) /
BigDecimal(12),
n = 12 * term,
numerator =
((BigDecimal.ONE + r).pow(n)) -
BigDecimal.ONE,
denominator = r * (BigDecimal.ONE + r).pow(n),
)

""".trimIndent(),
formattingOptions = Formatter.KOTLINLANG_FORMAT,
deduceMaxWidth = true,
)

@Test
fun `complex calls and calculation in named parameters without wrapping`() =
hick209 marked this conversation as resolved.
Show resolved Hide resolved
assertFormatted(
"""
calculateMath(
r = apr.sc(10) / BigDecimal(100) / BigDecimal(12),
n = 12 * term,
numerator = ((BigDecimal.ONE + r).pow(n)) - BigDecimal.ONE,
denominator = r * (BigDecimal.ONE + r).pow(n),
)

""".trimIndent(),
formattingOptions = Formatter.KOTLINLANG_FORMAT,
deduceMaxWidth = false,
)

@Test
fun `long call chains in named parameters`() =
hick209 marked this conversation as resolved.
Show resolved Hide resolved
assertFormatted(
"""
|/////////////////////////////////////////////////
|declareOne(
| kind = DeclarationKind.FIELD,
| modifiers = property.modifierList,
| valOrVarKeyword =
| property.valOrVarKeyword.text,
| multiline =
| property.one.two.three.four.five.six.seven
| .eight
| .nine
| .ten,
| typeParametersBlaBla =
| property.typeParameterList,
| receiver = property.receiverTypeReference,
| name = property.nameIdentifier?.text,
| type = property.typeReference,
| typeConstraintList =
| property.typeConstraintList,
| delegate = property.delegate,
| initializer = property.initializer,
|)
|""".trimMargin(),
formattingOptions = Formatter.GOOGLE_FORMAT,
deduceMaxWidth = true)

@Test
fun `Arguments are blocks`() =
assertFormatted(
Expand Down
Loading