Added test and asserts
This commit is contained in:
+2
@@ -85,6 +85,7 @@ class FilterTransformation(
|
|||||||
// we merge filter transformations here instead of FilterTransformation.mergeWithPrevious() because of filterIndexed that won't merge otherwise
|
// we merge filter transformations here instead of FilterTransformation.mergeWithPrevious() because of filterIndexed that won't merge otherwise
|
||||||
|
|
||||||
var (transformation, currentState) = matchOneTransformation(state) ?: return null
|
var (transformation, currentState) = matchOneTransformation(state) ?: return null
|
||||||
|
assert(currentState.indexVariable == state.indexVariable) // indexVariable should not change
|
||||||
|
|
||||||
if (transformation is FilterTransformation) {
|
if (transformation is FilterTransformation) {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -92,6 +93,7 @@ class FilterTransformation(
|
|||||||
|
|
||||||
val (nextTransformation, nextState) = matchOneTransformation(currentState) ?: break
|
val (nextTransformation, nextState) = matchOneTransformation(currentState) ?: break
|
||||||
if (nextTransformation !is FilterTransformation) break
|
if (nextTransformation !is FilterTransformation) break
|
||||||
|
assert(nextState.indexVariable == currentState.indexVariable) // indexVariable should not change
|
||||||
|
|
||||||
val indexVariable = transformation.indexVariable ?: nextTransformation.indexVariable
|
val indexVariable = transformation.indexVariable ?: nextTransformation.indexVariable
|
||||||
val mergedCondition = KtPsiFactory(state.outerLoop).createExpressionByPattern(
|
val mergedCondition = KtPsiFactory(state.outerLoop).createExpressionByPattern(
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// INTENTION_TEXT: "Replace with 'filterIndexed{}.firstOrNull()'"
|
||||||
|
fun foo(list: List<String>): String? {
|
||||||
|
var index2 = 0
|
||||||
|
<caret>for ((index1, s) in list.withIndex()) {
|
||||||
|
if (s.length > index1) continue
|
||||||
|
if (s.length < index2++) continue
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// INTENTION_TEXT: "Replace with 'filterIndexed{}.firstOrNull()'"
|
||||||
|
fun foo(list: List<String>): String? {
|
||||||
|
var index2 = 0
|
||||||
|
return list
|
||||||
|
.filterIndexed { index1, s -> s.length <= index1 && s.length >= index2++ }
|
||||||
|
.firstOrNull()
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user