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

BooleanExpressionRule fixes #1295

Merged
merged 10 commits into from
May 25, 2022

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@ class BooleanExpressionsRuleFixTest : FixTestBase("test/paragraph3/boolean_expre
fun `check same expressions`() {
fixAndCompare("SameExpressionsInConditionExpected.kt", "SameExpressionsInConditionTest.kt")
}

@Test
@Tag(WarningNames.COMPLEX_BOOLEAN_EXPRESSION)
fun `check substitution works properly`() {
fixAndCompare("SubstitutionIssueExpected.kt", "SubstitutionIssueTest.kt")
}

@Test
@Tag(WarningNames.COMPLEX_BOOLEAN_EXPRESSION)
fun `check ordering is persisted`() {
fixAndCompare("OrderIssueExpected.kt", "OrderIssueTest.kt")
}

@Test
@Tag(WarningNames.COMPLEX_BOOLEAN_EXPRESSION)
fun `check handling of negative expression`() {
fixAndCompare("NegativeExpressionExpected.kt", "NegativeExpressionTest.kt")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class BooleanExpressionsRuleWarnTest : LintTestBase(::BooleanExpressionsRule) {
// nested boolean expressions in lambdas
if (currentProperty.nextSibling { it.elementType == PROPERTY } == nextProperty) {}

if (!(rightSide == null || leftSide == null) &&
if (rightSide != null && leftSide != null &&
rightSide.size == leftSide.size &&
rightSide.zip(leftSide).all { (first, second) -> first.text == second.text }) {}

Expand Down Expand Up @@ -283,10 +283,11 @@ class BooleanExpressionsRuleWarnTest : LintTestBase(::BooleanExpressionsRule) {
val stream = ByteArrayOutputStream()
System.setErr(PrintStream(stream))
val node = KotlinParser().createNode(expression)
val map: java.util.HashMap<String, Char> = HashMap()
val result = BooleanExpressionsRule(emptyList()).formatBooleanExpressionAsString(node, map)
val rule = BooleanExpressionsRule(emptyList())
val map: BooleanExpressionsRule.ExpressionsReplacement = rule.ExpressionsReplacement()
val result = rule.formatBooleanExpressionAsString(node, map)
Assertions.assertEquals(expectedRepresentation, result)
Assertions.assertEquals(expectedMapSize, map.size)
Assertions.assertEquals(expectedMapSize, map.size())
System.setErr(System.err)
val stderr = stream.toString()
Assertions.assertTrue(stderr.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package test.paragraph3.boolean_expressions

fun foo() {
if (bar) {
}
if (bar) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package test.paragraph3.boolean_expressions

fun foo() {
if (bar && (!isEmpty() || isEmpty())) {
}
if (bar && (isEmpty() || !isEmpty())) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package test.paragraph3.boolean_expressions

fun foo() {
if (isB && isA && isC) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package test.paragraph3.boolean_expressions

fun foo() {
if (isB && isA && isC && (isEmpty() || !isEmpty())) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package test.paragraph3.boolean_expressions

fun foo() {
if (isABC_A && isABC_B && isABC_C) {
}
if (isAdd && isAdded()) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package test.paragraph3.boolean_expressions

fun foo() {
if (isABC_A && isABC_B && isABC_C && (isEmpty() || !isEmpty())) {
}
if (isAdd && isAdded() && (isEmpty() || !isEmpty())) {
}
}