diff --git a/src/jvmTest/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/bigtext/BigTextVerifyImpl.kt b/src/jvmTest/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/bigtext/BigTextVerifyImpl.kt index 19fb6992..c4b32a76 100644 --- a/src/jvmTest/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/bigtext/BigTextVerifyImpl.kt +++ b/src/jvmTest/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/bigtext/BigTextVerifyImpl.kt @@ -46,7 +46,7 @@ internal class BigTextVerifyImpl(bigTextImpl: BigTextImpl) : BigText { val originalLength: Int get() = length - transformOffsetsByPosition.values.sum() - private data class TransformOp(val originalRange: IntRange, val replaceMapping: BigTextTransformOffsetMapping) + private data class TransformOp(val originalRange: IntRange, val offsetMapping: BigTextTransformOffsetMapping) override fun buildString(): String { val r = bigTextImpl.buildString() @@ -86,6 +86,7 @@ internal class BigTextVerifyImpl(bigTextImpl: BigTextImpl) : BigText { println("VerifyImpl pos $pos offset $it") } stringImpl.insertAt(pos, text) +// transformOps += TransformOp(pos until pos + text.length, BigTextTransformOffsetMapping.WholeBlock) verify() return r } @@ -104,6 +105,7 @@ internal class BigTextVerifyImpl(bigTextImpl: BigTextImpl) : BigText { val offset = transformOffsetsByPosition.subMap(0, start).values.sum() stringImpl.delete(offset + start, offset + endExclusive) } + transformOps += TransformOp(start until endExclusive, BigTextTransformOffsetMapping.WholeBlock) println("new len = ${bigTextImpl.length}") verify() return r @@ -219,10 +221,10 @@ internal class BigTextVerifyImpl(bigTextImpl: BigTextImpl) : BigText { val mapped = i + offsetSum if (mapped > transformedPosition) { if (result != null) { - return transformOps.firstOrNull { it.replaceMapping == BigTextTransformOffsetMapping.WholeBlock && it.originalRange.first == start } + return transformOps.firstOrNull { it.offsetMapping == BigTextTransformOffsetMapping.WholeBlock && it.originalRange.first == start } ?.originalRange ?.endInclusive - ?.let { it + 1 } + ?.let { maxOf(it + 1, result!!) } ?: result } return i diff --git a/src/jvmTest/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/bigtext/transform/BigTextTransformPositionCalculatorTest.kt b/src/jvmTest/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/bigtext/transform/BigTextTransformPositionCalculatorTest.kt index f8a5e51a..cf15e87b 100644 --- a/src/jvmTest/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/bigtext/transform/BigTextTransformPositionCalculatorTest.kt +++ b/src/jvmTest/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/bigtext/transform/BigTextTransformPositionCalculatorTest.kt @@ -90,6 +90,22 @@ class BigTextTransformPositionCalculatorTest { v.verifyPositionCalculation() } + @ParameterizedTest + @ValueSource(ints = [1048576, 64, 16]) + fun transformDeleteWholeText(chunkSize: Int) { + val t = BigTextImpl(chunkSize = chunkSize).apply { + append("1234567890<234567890