0.0.8-SNAPSHOT fixed block indexes in merge3 resultб yet again
This commit is contained in:
parent
d60f90160b
commit
64df8ed9f2
@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "net.sergeych"
|
group = "net.sergeych"
|
||||||
version = "0.0.6-SNAPSHOT"
|
version = "0.0.8-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -20,15 +20,22 @@ class MergeResult<T>(
|
|||||||
val changedAreas: List<IntRange>,
|
val changedAreas: List<IntRange>,
|
||||||
val sourceIndices: MutableList<Int>,
|
val sourceIndices: MutableList<Int>,
|
||||||
) {
|
) {
|
||||||
|
fun oldIndexOf(i: Int) = sourceIndices.indexOf(i)
|
||||||
|
|
||||||
val blocks: List<MergedBlock<T>> by lazy {
|
val blocks: List<MergedBlock<T>> by lazy {
|
||||||
if (changedAreas.isEmpty())
|
if (changedAreas.isEmpty())
|
||||||
listOf(MergedBlock.Unchanged(merged, sourceIndices[0]))
|
listOf(MergedBlock.Unchanged(merged, oldIndexOf(0)))
|
||||||
else {
|
else {
|
||||||
val result = mutableListOf<MergedBlock<T>>()
|
val result = mutableListOf<MergedBlock<T>>()
|
||||||
var start = 0
|
var start = 0
|
||||||
for (r in changedAreas) {
|
for (r in changedAreas) {
|
||||||
if (start != r.start) {
|
if (start != r.start) {
|
||||||
result.add(MergedBlock.Unchanged(merged.slice(start until r.start), sourceIndices[start]))
|
result.add(
|
||||||
|
MergedBlock.Unchanged(
|
||||||
|
merged.slice(start until r.start),
|
||||||
|
oldIndexOf(start)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (!r.isEmpty()) {
|
if (!r.isEmpty()) {
|
||||||
result.add(MergedBlock.Resolved(merged.slice(r)))
|
result.add(MergedBlock.Resolved(merged.slice(r)))
|
||||||
|
@ -114,8 +114,22 @@ class BasicTest {
|
|||||||
val our = "lssdfasdwerwev".toList()
|
val our = "lssdfasdwerwev".toList()
|
||||||
val their = "lxcvasdfasdfs".toList()
|
val their = "lxcvasdfasdfs".toList()
|
||||||
val result = merge3(source, their, our)
|
val result = merge3(source, their, our)
|
||||||
println("got result")
|
println("got result: ${result.toTrace(source)}")
|
||||||
val unchanged = result.blocks.filter { it is MergedBlock.Unchanged }
|
println("got result: ${result.blocks}")
|
||||||
|
result.blocks.filter { it is MergedBlock.Unchanged }
|
||||||
|
assertTrue(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testMergeEmpty() {
|
||||||
|
Log.connectConsole()
|
||||||
|
val source = "".toList()
|
||||||
|
val our = "".toList()
|
||||||
|
val their = "".toList()
|
||||||
|
val result = merge3(source, their, our)
|
||||||
|
println("got result: ${result.toTrace(source)}")
|
||||||
|
println("got result: ${result.blocks}")
|
||||||
|
result.blocks.filter { it is MergedBlock.Unchanged }
|
||||||
assertTrue(true)
|
assertTrue(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user