From b1b7d8b04f1d2f4e51ac98380f2219f8a6c0497b Mon Sep 17 00:00:00 2001 From: Sunny Chung Date: Sun, 22 Sep 2024 00:53:08 +0800 Subject: [PATCH] add more test cases to BigText transform offset calculator tests --- .../test/bigtext/BigTextVerifyImpl.kt | 8 +- .../BigTextTransformPositionCalculatorTest.kt | 122 ++++++++++++++++++ 2 files changed, 127 insertions(+), 3 deletions(-) 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