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"
|
||||
version = "0.0.6-SNAPSHOT"
|
||||
version = "0.0.8-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -20,15 +20,22 @@ class MergeResult<T>(
|
||||
val changedAreas: List<IntRange>,
|
||||
val sourceIndices: MutableList<Int>,
|
||||
) {
|
||||
fun oldIndexOf(i: Int) = sourceIndices.indexOf(i)
|
||||
|
||||
val blocks: List<MergedBlock<T>> by lazy {
|
||||
if (changedAreas.isEmpty())
|
||||
listOf(MergedBlock.Unchanged(merged, sourceIndices[0]))
|
||||
listOf(MergedBlock.Unchanged(merged, oldIndexOf(0)))
|
||||
else {
|
||||
val result = mutableListOf<MergedBlock<T>>()
|
||||
var start = 0
|
||||
for (r in changedAreas) {
|
||||
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()) {
|
||||
result.add(MergedBlock.Resolved(merged.slice(r)))
|
||||
|
@ -114,8 +114,22 @@ class BasicTest {
|
||||
val our = "lssdfasdwerwev".toList()
|
||||
val their = "lxcvasdfasdfs".toList()
|
||||
val result = merge3(source, their, our)
|
||||
println("got result")
|
||||
val unchanged = result.blocks.filter { it is MergedBlock.Unchanged }
|
||||
println("got result: ${result.toTrace(source)}")
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user