diff: tests

This commit is contained in:
Aleksey Pivovarov
2015-09-16 14:34:26 +03:00
parent e3379d6783
commit fa2391132c
3 changed files with 101 additions and 10 deletions
@@ -209,7 +209,7 @@ public abstract class DiffTestCase : UsefulTestCase() {
f(data3, ThreeSide.RIGHT)
}
public fun invoke(side: ThreeSide): T? = side.select(data1, data2, data3)
public fun invoke(side: ThreeSide): T = side.select(data1, data2, data3) as T
override fun toString(): String {
return "($data1, $data2, $data3)"
@@ -52,9 +52,9 @@ public abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
var empty = true
var squashed = true
ThreeSide.values().forEach {
val start = starts(it)!!
val end = ends(it)!!
val last = lasts(it)!!
val start = starts(it)
val end = ends(it)
val last = lasts(it)
assertTrue(last <= start)
assertTrue(start <= end)
@@ -179,8 +179,8 @@ public abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
val starts = Trio(start1, start2, start3)
val ends = Trio(end1, end2, end3)
public fun start(side: ThreeSide): Int = this(side)!!.val1
public fun end(side: ThreeSide): Int = this(side)!!.val2
public fun start(side: ThreeSide): Int = this(side).val1
public fun end(side: ThreeSide): Int = this(side).val2
override fun toString(): String {
return "($start1, $end1) - ($start2, $end2) - ($start3, $end3)"
@@ -15,10 +15,12 @@
*/
package com.intellij.diff.comparison
import com.intellij.diff.DiffTestCase
import com.intellij.diff.assertEquals
import com.intellij.testFramework.UsefulTestCase
import com.intellij.diff.assertTrue
import com.intellij.diff.util.IntPair
public class ComparisonUtilTest : UsefulTestCase() {
public class ComparisonUtilTest : DiffTestCase() {
public fun testTrimEquals() {
doTestTrim(true, "", "")
doTestTrim(true, "", " ")
@@ -60,6 +62,89 @@ public class ComparisonUtilTest : UsefulTestCase() {
doTestTrim(false, "xyx", "xYx")
}
public fun testLineFragment() {
doTestLineFragment(
"", "x",
!0 - 0, !0 - 1,
!0 - 1, !0 - 1)
doTestLineFragment(
"x", "y",
!0 - 1, !0 - 1,
!0 - 1, !0 - 1)
doTestLineFragment(
"x_", "y_",
!0 - 2, !0 - 2,
!0 - 1, !0 - 1)
doTestLineFragment(
"x", "y_",
!0 - 1, !0 - 2,
!0 - 1, !0 - 2)
doTestLineFragment(
"x", "x_",
!1 - 1, !2 - 2,
!1 - 1, !1 - 2)
doTestLineFragment(
"x_y_z_", "x_Y_z_",
!2 - 4, !2 - 4,
!1 - 2, !1 - 2)
doTestLineFragment(
"x_y_z_", "x_y_Z_",
!4 - 6, !4 - 6,
!2 - 3, !2 - 3)
doTestLineFragment(
"x_y_z_", "x_y_Z_",
!4 - 6, !4 - 6,
!2 - 3, !2 - 3)
doTestLineFragment(
"x_y_z_", "x_y_Z",
!4 - 6, !4 - 5,
!2 - 4, !2 - 3)
doTestLineFragment(
"x_y_z", "x_y_Z_",
!4 - 5, !4 - 6,
!2 - 3, !2 - 4)
doTestLineFragment(
" ", "_ ",
!0 - 0, !0 - 1,
!0 - 0, !0 - 1)
doTestLineFragment(
" ", " _",
!1 - 1, !2 - 2,
!1 - 1, !1 - 2)
}
//
// Impl
//
private fun doTestLineFragment(string1: String, string2: String,
offsets1: IntPair, offsets2: IntPair,
lines1: IntPair, lines2: IntPair) {
val fragments = MANAGER.compareLines(parseSource(string1), parseSource(string2), ComparisonPolicy.DEFAULT, INDICATOR)
assertTrue(fragments.size() == 1, "Side: ${fragments.size()})")
val fragment = fragments.get(0)
assertEquals(offsets1.val1, fragment.getStartOffset1(), fragment.toString())
assertEquals(offsets1.val2, fragment.getEndOffset1(), fragment.toString())
assertEquals(offsets2.val1, fragment.getStartOffset2(), fragment.toString())
assertEquals(offsets2.val2, fragment.getEndOffset2(), fragment.toString())
assertEquals(lines1.val1, fragment.getStartLine1(), fragment.toString())
assertEquals(lines1.val2, fragment.getEndLine1(), fragment.toString())
assertEquals(lines2.val1, fragment.getStartLine2(), fragment.toString())
assertEquals(lines2.val2, fragment.getEndLine2(), fragment.toString())
}
private fun doTestTrim(expected: Boolean, string1: String, string2: String) {
doTest(expected, string1, string2, ComparisonPolicy.TRIM_WHITESPACES)
}
@@ -69,7 +154,13 @@ public class ComparisonUtilTest : UsefulTestCase() {
assertEquals(expected, result, "---\n" + string1 + "\n---\n" + string2 + "\n---")
}
companion object {
private val MANAGER = ComparisonManagerImpl()
//
// Helpers
//
public fun Int.not(): LineColHelper = LineColHelper(this)
public fun LineColHelper.minus(col: Int): IntPair = IntPair(this.line, col)
public inner class LineColHelper(val line: Int) {
}
}