mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: cleanup tests - remove unnecessary visibility modifiers
This commit is contained in:
@@ -31,7 +31,7 @@ import junit.framework.ComparisonFailure
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
public abstract class DiffTestCase : UsefulTestCase() {
|
||||
abstract class DiffTestCase : UsefulTestCase() {
|
||||
companion object {
|
||||
private val DEFAULT_CHAR_COUNT = 12
|
||||
private val DEFAULT_CHAR_TABLE: Map<Int, Char> = {
|
||||
@@ -41,11 +41,11 @@ public abstract class DiffTestCase : UsefulTestCase() {
|
||||
}()
|
||||
}
|
||||
|
||||
public val RNG: Random = Random()
|
||||
val RNG: Random = Random()
|
||||
private var gotSeedException = false
|
||||
|
||||
public val INDICATOR: ProgressIndicator = DumbProgressIndicator.INSTANCE
|
||||
public val MANAGER: ComparisonManagerImpl = ComparisonManagerImpl()
|
||||
val INDICATOR: ProgressIndicator = DumbProgressIndicator.INSTANCE
|
||||
val MANAGER: ComparisonManagerImpl = ComparisonManagerImpl()
|
||||
|
||||
|
||||
override fun setUp() {
|
||||
@@ -62,19 +62,19 @@ public abstract class DiffTestCase : UsefulTestCase() {
|
||||
// Assertions
|
||||
//
|
||||
|
||||
public fun assertTrue(actual: Boolean, message: String = "") {
|
||||
fun assertTrue(actual: Boolean, message: String = "") {
|
||||
assertTrue(message, actual)
|
||||
}
|
||||
|
||||
public fun assertEquals(expected: Any?, actual: Any?, message: String = "") {
|
||||
fun assertEquals(expected: Any?, actual: Any?, message: String = "") {
|
||||
assertEquals(message, expected, actual)
|
||||
}
|
||||
|
||||
public fun assertEquals(expected: CharSequence?, actual: CharSequence?, message: String = "") {
|
||||
fun assertEquals(expected: CharSequence?, actual: CharSequence?, message: String = "") {
|
||||
if (!StringUtil.equals(expected, actual)) throw ComparisonFailure(message, expected?.toString(), actual?.toString())
|
||||
}
|
||||
|
||||
public fun assertEqualsCharSequences(chunk1: CharSequence, chunk2: CharSequence, ignoreSpaces: Boolean, skipLastNewline: Boolean) {
|
||||
fun assertEqualsCharSequences(chunk1: CharSequence, chunk2: CharSequence, ignoreSpaces: Boolean, skipLastNewline: Boolean) {
|
||||
if (ignoreSpaces) {
|
||||
assertTrue(StringUtil.equalsIgnoreWhitespaces(chunk1, chunk2))
|
||||
} else {
|
||||
@@ -93,18 +93,18 @@ public abstract class DiffTestCase : UsefulTestCase() {
|
||||
// Parsing
|
||||
//
|
||||
|
||||
public fun textToReadableFormat(text: CharSequence?): String {
|
||||
fun textToReadableFormat(text: CharSequence?): String {
|
||||
if (text == null) return "null"
|
||||
return "'" + text.toString().replace('\n', '*').replace('\t', '+') + "'"
|
||||
}
|
||||
|
||||
public fun parseSource(string: CharSequence): String = string.toString().replace('_', '\n')
|
||||
fun parseSource(string: CharSequence): String = string.toString().replace('_', '\n')
|
||||
|
||||
public fun parseMatching(before: String, after: String): Couple<BitSet> {
|
||||
fun parseMatching(before: String, after: String): Couple<BitSet> {
|
||||
return Couple.of(parseMatching(before), parseMatching(after))
|
||||
}
|
||||
|
||||
public fun parseMatching(matching: String): BitSet {
|
||||
fun parseMatching(matching: String): BitSet {
|
||||
val set = BitSet()
|
||||
matching.filterNot { it == '.' }.forEachIndexed { i, c -> if (c != ' ') set.set(i) }
|
||||
return set
|
||||
@@ -114,17 +114,17 @@ public abstract class DiffTestCase : UsefulTestCase() {
|
||||
// Misc
|
||||
//
|
||||
|
||||
public fun getLineCount(document: Document): Int {
|
||||
fun getLineCount(document: Document): Int {
|
||||
return Math.max(1, document.lineCount)
|
||||
}
|
||||
|
||||
public infix fun Int.until(a: Int): IntRange = this..a - 1
|
||||
infix fun Int.until(a: Int): IntRange = this..a - 1
|
||||
|
||||
//
|
||||
// AutoTests
|
||||
//
|
||||
|
||||
public fun doAutoTest(seed: Long, runs: Int, test: (DebugData) -> Unit) {
|
||||
fun doAutoTest(seed: Long, runs: Int, test: (DebugData) -> Unit) {
|
||||
RNG.setSeed(seed)
|
||||
|
||||
var lastSeed: Long = -1
|
||||
@@ -149,7 +149,7 @@ public abstract class DiffTestCase : UsefulTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun generateText(maxLength: Int, charCount: Int, predefinedChars: Map<Int, Char>): String {
|
||||
fun generateText(maxLength: Int, charCount: Int, predefinedChars: Map<Int, Char>): String {
|
||||
val length = RNG.nextInt(maxLength + 1)
|
||||
val builder = StringBuilder(length)
|
||||
|
||||
@@ -161,11 +161,11 @@ public abstract class DiffTestCase : UsefulTestCase() {
|
||||
return builder.toString()
|
||||
}
|
||||
|
||||
public fun generateText(maxLength: Int): String {
|
||||
fun generateText(maxLength: Int): String {
|
||||
return generateText(maxLength, DEFAULT_CHAR_COUNT, DEFAULT_CHAR_TABLE)
|
||||
}
|
||||
|
||||
public fun getCurrentSeed(): Long {
|
||||
fun getCurrentSeed(): Long {
|
||||
if (gotSeedException) return -1
|
||||
try {
|
||||
val seedField = RNG.javaClass.getDeclaredField("seed")
|
||||
@@ -186,18 +186,18 @@ public abstract class DiffTestCase : UsefulTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public class DebugData() {
|
||||
class DebugData() {
|
||||
private val data: MutableList<Pair<String, Any>> = ArrayList()
|
||||
|
||||
public fun put(key: String, value: Any) {
|
||||
fun put(key: String, value: Any) {
|
||||
data.add(Pair(key, value))
|
||||
}
|
||||
|
||||
public fun reset() {
|
||||
fun reset() {
|
||||
data.clear()
|
||||
}
|
||||
|
||||
public fun dump() {
|
||||
fun dump() {
|
||||
data.forEach { println(it.first + ": " + it.second) }
|
||||
}
|
||||
}
|
||||
@@ -206,22 +206,22 @@ public abstract class DiffTestCase : UsefulTestCase() {
|
||||
// Helpers
|
||||
//
|
||||
|
||||
public open class Trio<T: Any>(val data1: T, val data2: T, val data3: T) {
|
||||
open class Trio<T : Any>(val data1: T, val data2: T, val data3: T) {
|
||||
companion object {
|
||||
public fun <V: Any> from(f: (ThreeSide) -> V): Trio<V> = Trio(f(ThreeSide.LEFT), f(ThreeSide.BASE), f(ThreeSide.RIGHT))
|
||||
fun <V : Any> from(f: (ThreeSide) -> V): Trio<V> = Trio(f(ThreeSide.LEFT), f(ThreeSide.BASE), f(ThreeSide.RIGHT))
|
||||
}
|
||||
|
||||
public fun <V: Any> map(f: (T) -> V): Trio<V> = Trio(f(data1), f(data2), f(data3))
|
||||
fun <V : Any> map(f: (T) -> V): Trio<V> = Trio(f(data1), f(data2), f(data3))
|
||||
|
||||
public fun <V: Any> map(f: (T, ThreeSide) -> V): Trio<V> = Trio(f(data1, ThreeSide.LEFT), f(data2, ThreeSide.BASE), f(data3, ThreeSide.RIGHT))
|
||||
fun <V : Any> map(f: (T, ThreeSide) -> V): Trio<V> = Trio(f(data1, ThreeSide.LEFT), f(data2, ThreeSide.BASE), f(data3, ThreeSide.RIGHT))
|
||||
|
||||
public fun forEach(f: (T, ThreeSide) -> Unit): Unit {
|
||||
fun forEach(f: (T, ThreeSide) -> Unit): Unit {
|
||||
f(data1, ThreeSide.LEFT)
|
||||
f(data2, ThreeSide.BASE)
|
||||
f(data3, ThreeSide.RIGHT)
|
||||
}
|
||||
|
||||
public operator fun invoke(side: ThreeSide): T = side.select(data1, data2, data3) as T
|
||||
operator fun invoke(side: ThreeSide): T = side.select(data1, data2, data3) as T
|
||||
|
||||
override fun toString(): String {
|
||||
return "($data1, $data2, $data3)"
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison
|
||||
|
||||
public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
public fun testEqualStrings() {
|
||||
class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
fun testEqualStrings() {
|
||||
chars {
|
||||
("" - "")
|
||||
("" - "").default()
|
||||
@@ -60,7 +60,7 @@ public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testTrivialCases() {
|
||||
fun testTrivialCases() {
|
||||
chars {
|
||||
("x" - "")
|
||||
("-" - "").default()
|
||||
@@ -106,7 +106,7 @@ public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testSimpleCases() {
|
||||
fun testSimpleCases() {
|
||||
chars {
|
||||
("xyx" - "xxx")
|
||||
(" - " - " - ").default()
|
||||
@@ -150,7 +150,7 @@ public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testWhitespaceChangesOnly() {
|
||||
fun testWhitespaceChangesOnly() {
|
||||
chars {
|
||||
(" x y z " - "xyz")
|
||||
("- - - -" - " ").default()
|
||||
@@ -194,7 +194,7 @@ public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testWhitespaceChanges() {
|
||||
fun testWhitespaceChanges() {
|
||||
chars {
|
||||
(" x " - "z")
|
||||
("---" - "-").default()
|
||||
@@ -224,7 +224,7 @@ public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testIgnoreInnerWhitespaces() {
|
||||
fun testIgnoreInnerWhitespaces() {
|
||||
chars {
|
||||
("x z y" - "xmn")
|
||||
(" ----" - " --").default()
|
||||
@@ -283,7 +283,7 @@ public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testEmptyRangePositions() {
|
||||
fun testEmptyRangePositions() {
|
||||
chars {
|
||||
("x y" - "x zy")
|
||||
default(ins(2, 2, 1))
|
||||
@@ -333,7 +333,7 @@ public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testAlgorithmSpecific() {
|
||||
fun testAlgorithmSpecific() {
|
||||
// This is a strange example: "ignore whitespace" produces lesser matching, than "Default".
|
||||
// This is fine, as the main goal of "ignore whitespaces" is to reduce 'noise' of diff, and 1 change is better than 3 changes
|
||||
// So we actually "ignore" whitespaces during comparison, rather than "mark all whitespaces as matched".
|
||||
@@ -345,7 +345,7 @@ public class CharComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testNonDeterministicCases() {
|
||||
fun testNonDeterministicCases() {
|
||||
chars {
|
||||
("x" - " ")
|
||||
ignore(del(0, 0, 1))
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison
|
||||
|
||||
public class ComparisonMergeUtilTest : ComparisonMergeUtilTestBase() {
|
||||
public fun testSimpleCases() {
|
||||
class ComparisonMergeUtilTest : ComparisonMergeUtilTestBase() {
|
||||
fun testSimpleCases() {
|
||||
chars {
|
||||
("" - "" - "")
|
||||
("" - "" - "").matching()
|
||||
@@ -63,7 +63,7 @@ public class ComparisonMergeUtilTest : ComparisonMergeUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testConflictTYpes() {
|
||||
fun testConflictTYpes() {
|
||||
chars {
|
||||
("abcd" - "abcd" - "abXcd")
|
||||
(" " - " " - " - ").matching()
|
||||
@@ -119,7 +119,7 @@ public class ComparisonMergeUtilTest : ComparisonMergeUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testBoundaryConflicts() {
|
||||
fun testBoundaryConflicts() {
|
||||
chars {
|
||||
("abcd" - "abcd" - "abcdx")
|
||||
(" " - " " - " -").matching()
|
||||
@@ -163,7 +163,7 @@ public class ComparisonMergeUtilTest : ComparisonMergeUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testMultipleChanges() {
|
||||
fun testMultipleChanges() {
|
||||
chars {
|
||||
("XXbXcXXeX" - "XyXzXXnXkX" - "XqXXeXrXX")
|
||||
(" - - - " - " - - - - " - " - - - ").matching()
|
||||
|
||||
+14
-14
@@ -25,7 +25,7 @@ import com.intellij.openapi.util.Couple
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import java.util.*
|
||||
|
||||
public abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
|
||||
abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
|
||||
private fun doCharTest(texts: Trio<Document>, expected: List<Change>?, matchings: Trio<BitSet>?) {
|
||||
val iterable1 = ByChar.compare(texts.data2.charsSequence, texts.data1.charsSequence, INDICATOR)
|
||||
val iterable2 = ByChar.compare(texts.data2.charsSequence, texts.data3.charsSequence, INDICATOR)
|
||||
@@ -95,7 +95,7 @@ public abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
|
||||
CHAR
|
||||
}
|
||||
|
||||
public inner class MergeTestBuilder(val type: TestType) {
|
||||
inner class MergeTestBuilder(val type: TestType) {
|
||||
private var isExecuted: Boolean = false
|
||||
|
||||
private var texts: Trio<Document>? = null
|
||||
@@ -103,11 +103,11 @@ public abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
|
||||
private var changes: List<Change>? = null
|
||||
private var matching: Trio<BitSet>? = null
|
||||
|
||||
public fun assertExecuted() {
|
||||
fun assertExecuted() {
|
||||
assertTrue(isExecuted)
|
||||
}
|
||||
|
||||
public fun test() {
|
||||
fun test() {
|
||||
isExecuted = true
|
||||
|
||||
assertTrue(changes != null || matching != null)
|
||||
@@ -118,15 +118,15 @@ public abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
|
||||
}
|
||||
|
||||
|
||||
public operator fun String.minus(v: String): Couple<String> {
|
||||
operator fun String.minus(v: String): Couple<String> {
|
||||
return Couple(this, v)
|
||||
}
|
||||
|
||||
public operator fun Couple<String>.minus(v: String): Helper {
|
||||
operator fun Couple<String>.minus(v: String): Helper {
|
||||
return Helper(Trio(this.first, this.second, v))
|
||||
}
|
||||
|
||||
public inner class Helper(val texts: Trio<String>) {
|
||||
inner class Helper(val texts: Trio<String>) {
|
||||
init {
|
||||
val builder = this@MergeTestBuilder
|
||||
if (builder.texts == null) {
|
||||
@@ -134,23 +134,23 @@ public abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun matching() {
|
||||
fun matching() {
|
||||
matching = texts.map { it -> parseMatching(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public fun changes(vararg expected: Change): Unit {
|
||||
fun changes(vararg expected: Change): Unit {
|
||||
changes = ContainerUtil.list(*expected)
|
||||
}
|
||||
|
||||
|
||||
public fun mod(line1: Int, line2: Int, line3: Int, count1: Int, count2: Int, count3: Int): Change {
|
||||
fun mod(line1: Int, line2: Int, line3: Int, count1: Int, count2: Int, count3: Int): Change {
|
||||
return Change(line1, line1 + count1, line2, line2 + count2, line3, line3 + count3)
|
||||
}
|
||||
}
|
||||
|
||||
public fun chars(f: MergeTestBuilder.() -> Unit) {
|
||||
fun chars(f: MergeTestBuilder.() -> Unit) {
|
||||
doTest(TestType.CHAR, f)
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public abstract class ComparisonMergeUtilTestBase : DiffTestCase() {
|
||||
}
|
||||
|
||||
|
||||
public class Change(start1: Int, end1: Int, start2: Int, end2: Int, start3: Int, end3: Int)
|
||||
class Change(start1: Int, end1: Int, start2: Int, end2: Int, start3: Int, end3: Int)
|
||||
: Trio<IntPair>(IntPair(start1, end1), IntPair(start2, end2), IntPair(start3, end3)) {
|
||||
|
||||
val start1 = start(ThreeSide.LEFT)
|
||||
@@ -175,8 +175,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
|
||||
fun start(side: ThreeSide): Int = this(side).val1
|
||||
fun end(side: ThreeSide): Int = this(side).val2
|
||||
|
||||
override fun toString(): String {
|
||||
return "($start1, $end1) - ($start2, $end2) - ($start3, $end3)"
|
||||
|
||||
@@ -25,24 +25,24 @@ import com.intellij.openapi.util.Couple
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
public class ComparisonUtilAutoTest : DiffTestCase() {
|
||||
public fun testChar() {
|
||||
class ComparisonUtilAutoTest : DiffTestCase() {
|
||||
fun testChar() {
|
||||
doTestChar(System.currentTimeMillis(), 30, 30)
|
||||
}
|
||||
|
||||
public fun testWord() {
|
||||
fun testWord() {
|
||||
doTestWord(System.currentTimeMillis(), 30, 300)
|
||||
}
|
||||
|
||||
public fun testLine() {
|
||||
fun testLine() {
|
||||
doTestLine(System.currentTimeMillis(), 30, 300)
|
||||
}
|
||||
|
||||
public fun testLineSquashed() {
|
||||
fun testLineSquashed() {
|
||||
doTestLineSquashed(System.currentTimeMillis(), 30, 300)
|
||||
}
|
||||
|
||||
public fun testLineTrimSquashed() {
|
||||
fun testLineTrimSquashed() {
|
||||
doTestLineTrimSquashed(System.currentTimeMillis(), 30, 300)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.intellij.diff.comparison
|
||||
import com.intellij.diff.DiffTestCase
|
||||
import com.intellij.diff.util.IntPair
|
||||
|
||||
public class ComparisonUtilTest : DiffTestCase() {
|
||||
public fun testTrimEquals() {
|
||||
class ComparisonUtilTest : DiffTestCase() {
|
||||
fun testTrimEquals() {
|
||||
doTestTrim(true, "", "")
|
||||
doTestTrim(true, "", " ")
|
||||
doTestTrim(true, " ", " ")
|
||||
@@ -60,7 +60,7 @@ public class ComparisonUtilTest : DiffTestCase() {
|
||||
doTestTrim(false, "xyx", "xYx")
|
||||
}
|
||||
|
||||
public fun testLineFragment() {
|
||||
fun testLineFragment() {
|
||||
doTestLineFragment(
|
||||
"", "x",
|
||||
!0 - 0, !0 - 1,
|
||||
@@ -156,9 +156,9 @@ public class ComparisonUtilTest : DiffTestCase() {
|
||||
// Helpers
|
||||
//
|
||||
|
||||
public operator fun Int.not(): LineColHelper = LineColHelper(this)
|
||||
public operator fun LineColHelper.minus(col: Int): IntPair = IntPair(this.line, col)
|
||||
operator fun Int.not(): LineColHelper = LineColHelper(this)
|
||||
operator fun LineColHelper.minus(col: Int): IntPair = IntPair(this.line, col)
|
||||
|
||||
public inner class LineColHelper(val line: Int) {
|
||||
inner class LineColHelper(val line: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.intellij.openapi.util.Couple
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import java.util.*
|
||||
|
||||
public abstract class ComparisonUtilTestBase : DiffTestCase() {
|
||||
abstract class ComparisonUtilTestBase : DiffTestCase() {
|
||||
private fun doLineTest(before: Document, after: Document, expected: List<Change>?, policy: ComparisonPolicy) {
|
||||
val fragments = MANAGER.compareLines(before.charsSequence, after.charsSequence, policy, INDICATOR)
|
||||
checkConsistency(fragments, before, after)
|
||||
@@ -159,7 +159,7 @@ public abstract class ComparisonUtilTestBase : DiffTestCase() {
|
||||
LINE, WORD, CHAR, SPLITTER
|
||||
}
|
||||
|
||||
public inner class TestBuilder(private val type: TestType) {
|
||||
inner class TestBuilder(private val type: TestType) {
|
||||
private var isExecuted: Boolean = false
|
||||
|
||||
private var before: Document? = null
|
||||
@@ -188,7 +188,7 @@ public abstract class ComparisonUtilTestBase : DiffTestCase() {
|
||||
ComparisonPolicy.DEFAULT -> defaultMatching
|
||||
}
|
||||
|
||||
public fun assertExecuted() {
|
||||
fun assertExecuted() {
|
||||
assertTrue(isExecuted)
|
||||
}
|
||||
|
||||
@@ -217,31 +217,31 @@ public abstract class ComparisonUtilTestBase : DiffTestCase() {
|
||||
}
|
||||
|
||||
|
||||
public fun testAll() {
|
||||
fun testAll() {
|
||||
testDefault()
|
||||
testTrim()
|
||||
testIgnore()
|
||||
}
|
||||
|
||||
public fun testDefault() {
|
||||
fun testDefault() {
|
||||
run(ComparisonPolicy.DEFAULT)
|
||||
}
|
||||
|
||||
public fun testTrim() {
|
||||
fun testTrim() {
|
||||
if (type == TestType.CHAR) return // not supported
|
||||
run(ComparisonPolicy.TRIM_WHITESPACES)
|
||||
}
|
||||
|
||||
public fun testIgnore() {
|
||||
fun testIgnore() {
|
||||
run(ComparisonPolicy.IGNORE_WHITESPACES)
|
||||
}
|
||||
|
||||
|
||||
public operator fun String.minus(v: String): Helper {
|
||||
operator fun String.minus(v: String): Helper {
|
||||
return Helper(this, v)
|
||||
}
|
||||
|
||||
public inner class Helper(val before: String, val after: String) {
|
||||
inner class Helper(val before: String, val after: String) {
|
||||
init {
|
||||
val builder = this@TestBuilder
|
||||
if (builder.before == null && builder.after == null) {
|
||||
@@ -250,68 +250,68 @@ public abstract class ComparisonUtilTestBase : DiffTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun plainSource() {
|
||||
fun plainSource() {
|
||||
val builder = this@TestBuilder
|
||||
builder.before = DocumentImpl(before)
|
||||
builder.after = DocumentImpl(after)
|
||||
}
|
||||
|
||||
public fun default() {
|
||||
fun default() {
|
||||
defaultMatching = parseMatching(before, after)
|
||||
}
|
||||
|
||||
public fun trim() {
|
||||
fun trim() {
|
||||
trimMatching = parseMatching(before, after)
|
||||
}
|
||||
|
||||
public fun ignore() {
|
||||
fun ignore() {
|
||||
ignoreMatching = parseMatching(before, after)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public fun default(vararg expected: Change): Unit {
|
||||
fun default(vararg expected: Change): Unit {
|
||||
defaultChanges = ContainerUtil.list(*expected)
|
||||
}
|
||||
|
||||
public fun trim(vararg expected: Change): Unit {
|
||||
fun trim(vararg expected: Change): Unit {
|
||||
trimChanges = ContainerUtil.list(*expected)
|
||||
}
|
||||
|
||||
public fun ignore(vararg expected: Change): Unit {
|
||||
fun ignore(vararg expected: Change): Unit {
|
||||
ignoreChanges = ContainerUtil.list(*expected)
|
||||
}
|
||||
|
||||
public fun mod(line1: Int, line2: Int, count1: Int, count2: Int): Change {
|
||||
fun mod(line1: Int, line2: Int, count1: Int, count2: Int): Change {
|
||||
assert(count1 != 0)
|
||||
assert(count2 != 0)
|
||||
return Change(line1, line1 + count1, line2, line2 + count2)
|
||||
}
|
||||
|
||||
public fun del(line1: Int, line2: Int, count1: Int): Change {
|
||||
fun del(line1: Int, line2: Int, count1: Int): Change {
|
||||
assert(count1 != 0)
|
||||
return Change(line1, line1 + count1, line2, line2)
|
||||
}
|
||||
|
||||
public fun ins(line1: Int, line2: Int, count2: Int): Change {
|
||||
fun ins(line1: Int, line2: Int, count2: Int): Change {
|
||||
assert(count2 != 0)
|
||||
return Change(line1, line1, line2, line2 + count2)
|
||||
}
|
||||
|
||||
|
||||
public fun postprocess(squash: Boolean, trim: Boolean): Unit {
|
||||
fun postprocess(squash: Boolean, trim: Boolean): Unit {
|
||||
shouldSquash = squash
|
||||
shouldTrim = trim
|
||||
}
|
||||
}
|
||||
|
||||
public fun lines(f: TestBuilder.() -> Unit): Unit = doTest(TestType.LINE, f)
|
||||
fun lines(f: TestBuilder.() -> Unit): Unit = doTest(TestType.LINE, f)
|
||||
|
||||
public fun words(f: TestBuilder.() -> Unit): Unit = doTest(TestType.WORD, f)
|
||||
fun words(f: TestBuilder.() -> Unit): Unit = doTest(TestType.WORD, f)
|
||||
|
||||
public fun chars(f: TestBuilder.() -> Unit): Unit = doTest(TestType.CHAR, f)
|
||||
fun chars(f: TestBuilder.() -> Unit): Unit = doTest(TestType.CHAR, f)
|
||||
|
||||
public fun splitter(squash: Boolean = false, trim: Boolean = false, f: TestBuilder.() -> Unit): Unit {
|
||||
fun splitter(squash: Boolean = false, trim: Boolean = false, f: TestBuilder.() -> Unit): Unit {
|
||||
doTest(TestType.SPLITTER, {
|
||||
postprocess(squash, trim)
|
||||
f()
|
||||
@@ -328,7 +328,7 @@ public abstract class ComparisonUtilTestBase : DiffTestCase() {
|
||||
// Helpers
|
||||
//
|
||||
|
||||
public data class Change(val start1: Int, val end1: Int, val start2: Int, val end2: Int) {
|
||||
data class Change(val start1: Int, val end1: Int, val start2: Int, val end2: Int) {
|
||||
override fun toString(): String {
|
||||
return "($start1, $end1) - ($start2, $end2)"
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison
|
||||
|
||||
public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
public fun testEqualStrings() {
|
||||
class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
fun testEqualStrings() {
|
||||
lines {
|
||||
("" - "")
|
||||
default()
|
||||
@@ -48,7 +48,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testTrivialCases() {
|
||||
fun testTrivialCases() {
|
||||
lines {
|
||||
("x_" - "y_")
|
||||
default(mod(0, 0, 1, 1))
|
||||
@@ -98,7 +98,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testSimpleCases() {
|
||||
fun testSimpleCases() {
|
||||
lines {
|
||||
("x_z" - "y_z")
|
||||
default(mod(0, 0, 1, 1))
|
||||
@@ -142,7 +142,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testEmptyLastLine() {
|
||||
fun testEmptyLastLine() {
|
||||
lines {
|
||||
("x_" - "")
|
||||
default(del(0, 0, 1))
|
||||
@@ -168,7 +168,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testWhitespaceOnlyChanges() {
|
||||
fun testWhitespaceOnlyChanges() {
|
||||
lines {
|
||||
("x " - " x")
|
||||
default(mod(0, 0, 1, 1))
|
||||
@@ -213,7 +213,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testAlgorithmSpecific() {
|
||||
fun testAlgorithmSpecific() {
|
||||
lines {
|
||||
("x_y_z_AAAAA" - "AAAAA_x_y_z")
|
||||
default(del(0, 0, 3), ins(4, 1, 3))
|
||||
@@ -240,7 +240,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testNonDeterministicCases() {
|
||||
fun testNonDeterministicCases() {
|
||||
lines {
|
||||
("" - "__")
|
||||
default(ins(1, 1, 2))
|
||||
@@ -254,7 +254,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun `test regression - shifted similar lines should be matched as a single change, not insertion-deletion`() {
|
||||
fun `test regression - shifted similar lines should be matched as a single change, not insertion-deletion`() {
|
||||
lines {
|
||||
(" X_ X" - " X_ X")
|
||||
default(mod(0, 0, 2, 2))
|
||||
@@ -262,7 +262,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun `test prefer chunks bounded by empty line`() {
|
||||
fun `test prefer chunks bounded by empty line`() {
|
||||
lines {
|
||||
("A_B_o_o_Y_Z_ _A_B_z_z_Y_Z" - "A_B_o_o_Y_Z_ _A_B_u_u_Y_Z_ _A_B_z_z_Y_Z")
|
||||
default(ins(7, 7, 7))
|
||||
@@ -282,7 +282,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun `test prefer smaller amount of chunks`() {
|
||||
fun `test prefer smaller amount of chunks`() {
|
||||
lines() {
|
||||
("X_A_X_Y_" - "X_Y_")
|
||||
default(del(0, 0, 2))
|
||||
@@ -303,7 +303,7 @@ public class LineComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun `test regression - can trim chunks after 'compareTwoSteps'`() {
|
||||
fun `test regression - can trim chunks after 'compareTwoSteps'`() {
|
||||
lines {
|
||||
("q__7_ 6_ 7" - "_7")
|
||||
default(del(0, 0, 1), del(3, 2, 2))
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison
|
||||
|
||||
public class SplitComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
public fun testSplitter() {
|
||||
class SplitComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
fun testSplitter() {
|
||||
splitter {
|
||||
("x" - "z")
|
||||
default(mod(0, 0, 1, 1))
|
||||
@@ -76,7 +76,7 @@ public class SplitComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testSquash() {
|
||||
fun testSquash() {
|
||||
splitter(squash = true) {
|
||||
("x" - "z")
|
||||
default(mod(0, 0, 1, 1))
|
||||
@@ -105,7 +105,7 @@ public class SplitComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testTrim() {
|
||||
fun testTrim() {
|
||||
splitter(trim = true) {
|
||||
("_" - " _ ")
|
||||
default(mod(0, 0, 2, 2))
|
||||
|
||||
@@ -18,10 +18,10 @@ package com.intellij.diff.comparison
|
||||
import com.intellij.diff.DiffTestCase
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
public class TrimUtilTest : DiffTestCase() {
|
||||
class TrimUtilTest : DiffTestCase() {
|
||||
private val PUNCTUATION = "(){}[],./?`~!@#$%^&*-=+|\\;:'\"<>";
|
||||
|
||||
public fun testPunctuation() {
|
||||
fun testPunctuation() {
|
||||
for (c in Character.MIN_VALUE..Character.MAX_VALUE) {
|
||||
doCheckPunctuation(c)
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison
|
||||
|
||||
public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
public fun testSimpleCases() {
|
||||
class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
fun testSimpleCases() {
|
||||
words {
|
||||
("x z" - "y z")
|
||||
("- " - "- ").default()
|
||||
@@ -83,7 +83,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testPunctuation() {
|
||||
fun testPunctuation() {
|
||||
words {
|
||||
(" x.z.x " - "x..x")
|
||||
("- - -" - " ").default()
|
||||
@@ -136,7 +136,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testOldDiffBug() {
|
||||
fun testOldDiffBug() {
|
||||
words {
|
||||
("x'y'>" - "x'>")
|
||||
(" -- " - " ").default()
|
||||
@@ -150,7 +150,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testWhitespaceOnlyChanges() {
|
||||
fun testWhitespaceOnlyChanges() {
|
||||
words {
|
||||
("x =z" - "x= z")
|
||||
(" -- " - " -- ").default()
|
||||
@@ -166,7 +166,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testNewlines() {
|
||||
fun testNewlines() {
|
||||
words {
|
||||
(" x _ y _ z " - "x z")
|
||||
("- ------ -" - " ").default()
|
||||
@@ -184,7 +184,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testFixedBugs() {
|
||||
fun testFixedBugs() {
|
||||
words {
|
||||
(".! " - ". y!")
|
||||
(" -" - " --- ").default()
|
||||
@@ -210,7 +210,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testInnerWhitespaces() {
|
||||
fun testInnerWhitespaces() {
|
||||
words {
|
||||
("<< x >>" - "<.<>.>")
|
||||
(" --- " - " - - ").default()
|
||||
@@ -248,7 +248,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testAlgorithmSpecific() {
|
||||
fun testAlgorithmSpecific() {
|
||||
// prefer words over punctuation
|
||||
words {
|
||||
("...x" - "x...")
|
||||
@@ -301,7 +301,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun `test legacy cases from ByWordTest`() {
|
||||
fun `test legacy cases from ByWordTest`() {
|
||||
words {
|
||||
("abc def, 123" - "ab def, 12")
|
||||
("--- ---" - "-- --").default()
|
||||
|
||||
@@ -19,13 +19,13 @@ import com.intellij.diff.DiffTestCase
|
||||
import com.intellij.diff.util.Side
|
||||
import com.intellij.diff.util.ThreeSide
|
||||
|
||||
public class MergeAutoTest : MergeTestBase() {
|
||||
class MergeAutoTest : MergeTestBase() {
|
||||
companion object {
|
||||
private val MODIFICATION_CYCLE_COUNT = 5
|
||||
private val MODIFICATION_CYCLE_SIZE = 3
|
||||
}
|
||||
|
||||
public fun testUndo() {
|
||||
fun testUndo() {
|
||||
doUndoTest(System.currentTimeMillis(), 10, 300)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import com.intellij.diff.util.Side
|
||||
import com.intellij.diff.util.TextDiffType.*
|
||||
import com.intellij.openapi.diff.DiffBundle
|
||||
|
||||
public class MergeTest : MergeTestBase() {
|
||||
public fun testChangeTypes() {
|
||||
class MergeTest : MergeTestBase() {
|
||||
fun testChangeTypes() {
|
||||
test ("", "", "", 0) {
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class MergeTest : MergeTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testLastLine() {
|
||||
fun testLastLine() {
|
||||
test1 ("x", "x_", "x") {
|
||||
0.assertType(DELETED, BOTH)
|
||||
0.assertContent("", 1, 2)
|
||||
@@ -144,7 +144,7 @@ public class MergeTest : MergeTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testModifications() {
|
||||
fun testModifications() {
|
||||
test1 ("x", "x", "y") {
|
||||
0.apply(Side.RIGHT)
|
||||
0.assertResolved(BOTH)
|
||||
@@ -242,7 +242,7 @@ public class MergeTest : MergeTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testModificationsIgnore() {
|
||||
fun testModificationsIgnore() {
|
||||
test1 ("x", "x", "y") {
|
||||
0.ignore(Side.RIGHT)
|
||||
0.assertResolved(BOTH)
|
||||
@@ -320,7 +320,7 @@ public class MergeTest : MergeTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testModificationsModifiers() {
|
||||
fun testModificationsModifiers() {
|
||||
test1 ("x", "x", "y") {
|
||||
0.apply(Side.RIGHT, true)
|
||||
0.assertResolved(BOTH)
|
||||
@@ -354,7 +354,7 @@ public class MergeTest : MergeTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testUndoSimple() {
|
||||
fun testUndoSimple() {
|
||||
test1 ("x", "y", "z") {
|
||||
checkUndo(1) {
|
||||
0.apply(Side.RIGHT)
|
||||
@@ -435,7 +435,7 @@ public class MergeTest : MergeTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testRangeModification() {
|
||||
fun testRangeModification() {
|
||||
test1("X_x_y_z_Y", "X_a_b_c_Y", "X_x_y_z_Y") {
|
||||
0.assertContent("a_b_c", 1, 4)
|
||||
checkUndo(1) { replaceText(!2 - 0, !2 - 1, "D") }
|
||||
@@ -499,7 +499,7 @@ public class MergeTest : MergeTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun testNonConflictsActions() {
|
||||
fun testNonConflictsActions() {
|
||||
val applyAllTitle = DiffBundle.message("merge.dialog.apply.all.non.conflicting.changes.action.name")
|
||||
val applyLeftTitle = DiffBundle.message("merge.dialog.apply.left.non.conflicting.changes.action.name")
|
||||
val applyRightTitle = DiffBundle.message("merge.dialog.apply.right.non.conflicting.changes.action.name")
|
||||
|
||||
@@ -42,7 +42,7 @@ import com.intellij.testFramework.fixtures.IdeaProjectTestFixture
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
|
||||
import com.intellij.util.ui.UIUtil
|
||||
|
||||
public abstract class MergeTestBase : DiffTestCase() {
|
||||
abstract class MergeTestBase : DiffTestCase() {
|
||||
private var projectFixture: IdeaProjectTestFixture? = null
|
||||
private var project: Project? = null
|
||||
|
||||
@@ -59,19 +59,19 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
public fun test1(left: String, base: String, right: String, f: TestBuilder.() -> Unit) {
|
||||
fun test1(left: String, base: String, right: String, f: TestBuilder.() -> Unit) {
|
||||
test(left, base, right, 1, f)
|
||||
}
|
||||
|
||||
public fun test2(left: String, base: String, right: String, f: TestBuilder.() -> Unit) {
|
||||
fun test2(left: String, base: String, right: String, f: TestBuilder.() -> Unit) {
|
||||
test(left, base, right, 2, f)
|
||||
}
|
||||
|
||||
public fun testN(left: String, base: String, right: String, f: TestBuilder.() -> Unit) {
|
||||
fun testN(left: String, base: String, right: String, f: TestBuilder.() -> Unit) {
|
||||
test(left, base, right, -1, f)
|
||||
}
|
||||
|
||||
public fun test(left: String, base: String, right: String, changesCount: Int, f: TestBuilder.() -> Unit) {
|
||||
fun test(left: String, base: String, right: String, changesCount: Int, f: TestBuilder.() -> Unit) {
|
||||
val contentFactory = DiffContentFactoryImpl()
|
||||
val leftContent: DocumentContent = contentFactory.create(parseSource(left))
|
||||
val baseContent: DocumentContent = contentFactory.create(parseSource(base))
|
||||
@@ -95,27 +95,27 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public inner class TestBuilder(public val mergeViewer: TextMergeViewer, private val actions: List<AnAction>) {
|
||||
public val viewer: MyThreesideViewer = mergeViewer.viewer
|
||||
public val changes: List<TextMergeChange> = viewer.getAllChanges()
|
||||
public val editor: EditorEx = viewer.getEditor(ThreeSide.BASE)
|
||||
public val document: Document = editor.document
|
||||
inner class TestBuilder(val mergeViewer: TextMergeViewer, private val actions: List<AnAction>) {
|
||||
val viewer: MyThreesideViewer = mergeViewer.viewer
|
||||
val changes: List<TextMergeChange> = viewer.getAllChanges()
|
||||
val editor: EditorEx = viewer.getEditor(ThreeSide.BASE)
|
||||
val document: Document = editor.document
|
||||
|
||||
private val textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
|
||||
private val undoManager = UndoManager.getInstance(project!!)
|
||||
|
||||
public fun change(num: Int): TextMergeChange {
|
||||
fun change(num: Int): TextMergeChange {
|
||||
if (changes.size < num) throw Exception("changes: ${changes.size}, index: $num")
|
||||
return changes[num]
|
||||
}
|
||||
|
||||
public fun activeChanges(): List<TextMergeChange> = viewer.getChanges()
|
||||
fun activeChanges(): List<TextMergeChange> = viewer.getChanges()
|
||||
|
||||
//
|
||||
// Actions
|
||||
//
|
||||
|
||||
public fun runActionByTitle(name: String): Boolean {
|
||||
fun runActionByTitle(name: String): Boolean {
|
||||
val action = actions.filter { name.equals(it.getTemplatePresentation().getText()) }
|
||||
assertTrue(action.size == 1, action.toString())
|
||||
return runAction(action[0])
|
||||
@@ -133,26 +133,26 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
// Modification
|
||||
//
|
||||
|
||||
public fun command(affected: TextMergeChange, f: () -> Unit): Unit {
|
||||
fun command(affected: TextMergeChange, f: () -> Unit): Unit {
|
||||
command(listOf(affected), f)
|
||||
}
|
||||
|
||||
public fun command(affected: List<TextMergeChange>? = null, f: () -> Unit): Unit {
|
||||
fun command(affected: List<TextMergeChange>? = null, f: () -> Unit): Unit {
|
||||
viewer.executeMergeCommand(null, affected, f)
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
}
|
||||
|
||||
public fun write(f: () -> Unit): Unit {
|
||||
fun write(f: () -> Unit): Unit {
|
||||
ApplicationManager.getApplication().runWriteAction({ CommandProcessor.getInstance().executeCommand(project, f, null, null) })
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
}
|
||||
|
||||
public fun Int.ignore(side: Side, modifier: Boolean = false) {
|
||||
fun Int.ignore(side: Side, modifier: Boolean = false) {
|
||||
val change = change(this)
|
||||
command(change) { viewer.ignoreChange(change, side, modifier) }
|
||||
}
|
||||
|
||||
public fun Int.apply(side: Side, modifier: Boolean = false) {
|
||||
fun Int.apply(side: Side, modifier: Boolean = false) {
|
||||
val change = change(this)
|
||||
command(change) { viewer.replaceChange(change, side, modifier) }
|
||||
}
|
||||
@@ -161,49 +161,49 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
// Text modification
|
||||
//
|
||||
|
||||
public fun insertText(offset: Int, newContent: CharSequence) {
|
||||
fun insertText(offset: Int, newContent: CharSequence) {
|
||||
replaceText(offset, offset, newContent)
|
||||
}
|
||||
|
||||
public fun deleteText(startOffset: Int, endOffset: Int) {
|
||||
fun deleteText(startOffset: Int, endOffset: Int) {
|
||||
replaceText(startOffset, endOffset, "")
|
||||
}
|
||||
|
||||
public fun replaceText(startOffset: Int, endOffset: Int, newContent: CharSequence) {
|
||||
fun replaceText(startOffset: Int, endOffset: Int, newContent: CharSequence) {
|
||||
write { document.replaceString(startOffset, endOffset, parseSource(newContent)) }
|
||||
}
|
||||
|
||||
public fun insertText(offset: LineCol, newContent: CharSequence) {
|
||||
fun insertText(offset: LineCol, newContent: CharSequence) {
|
||||
replaceText(offset.toOffset(), offset.toOffset(), newContent)
|
||||
}
|
||||
|
||||
public fun deleteText(startOffset: LineCol, endOffset: LineCol) {
|
||||
fun deleteText(startOffset: LineCol, endOffset: LineCol) {
|
||||
replaceText(startOffset.toOffset(), endOffset.toOffset(), "")
|
||||
}
|
||||
|
||||
public fun replaceText(startOffset: LineCol, endOffset: LineCol, newContent: CharSequence) {
|
||||
fun replaceText(startOffset: LineCol, endOffset: LineCol, newContent: CharSequence) {
|
||||
write { replaceText(startOffset.toOffset(), endOffset.toOffset(), newContent) }
|
||||
}
|
||||
|
||||
public fun replaceText(oldContent: CharSequence, newContent: CharSequence) {
|
||||
fun replaceText(oldContent: CharSequence, newContent: CharSequence) {
|
||||
write {
|
||||
val range = findRange(parseSource(oldContent))
|
||||
replaceText(range.first, range.second, newContent)
|
||||
}
|
||||
}
|
||||
|
||||
public fun deleteText(oldContent: CharSequence) {
|
||||
fun deleteText(oldContent: CharSequence) {
|
||||
write {
|
||||
val range = findRange(parseSource(oldContent))
|
||||
replaceText(range.first, range.second, "")
|
||||
}
|
||||
}
|
||||
|
||||
public fun insertTextBefore(oldContent: CharSequence, newContent: CharSequence) {
|
||||
fun insertTextBefore(oldContent: CharSequence, newContent: CharSequence) {
|
||||
write { insertText(findRange(parseSource(oldContent)).first, newContent) }
|
||||
}
|
||||
|
||||
public fun insertTextAfter(oldContent: CharSequence, newContent: CharSequence) {
|
||||
fun insertTextAfter(oldContent: CharSequence, newContent: CharSequence) {
|
||||
write { insertText(findRange(parseSource(oldContent)).second, newContent) }
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
// Undo
|
||||
//
|
||||
|
||||
public fun undo(count: Int = 1) {
|
||||
fun undo(count: Int = 1) {
|
||||
if (count == -1) {
|
||||
while (undoManager.isUndoAvailable(textEditor)) {
|
||||
undoManager.undo(textEditor)
|
||||
@@ -234,7 +234,7 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun redo(count: Int = 1) {
|
||||
fun redo(count: Int = 1) {
|
||||
if (count == -1) {
|
||||
while (undoManager.isRedoAvailable(textEditor)) {
|
||||
undoManager.redo(textEditor)
|
||||
@@ -248,7 +248,7 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun checkUndo(count: Int = -1, f: TestBuilder.() -> Unit) {
|
||||
fun checkUndo(count: Int = -1, f: TestBuilder.() -> Unit) {
|
||||
val initialState = ViewerState.recordState(viewer)
|
||||
f()
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
@@ -271,23 +271,23 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
// Checks
|
||||
//
|
||||
|
||||
public fun assertChangesCount(expected: Int) {
|
||||
fun assertChangesCount(expected: Int) {
|
||||
if (expected == -1) return
|
||||
val actual = activeChanges().size
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
public fun Int.assertType(type: TextDiffType, changeType: SidesState) {
|
||||
fun Int.assertType(type: TextDiffType, changeType: SidesState) {
|
||||
assertType(type)
|
||||
assertType(changeType)
|
||||
}
|
||||
|
||||
public fun Int.assertType(type: TextDiffType) {
|
||||
fun Int.assertType(type: TextDiffType) {
|
||||
val change = change(this)
|
||||
assertEquals(change.diffType, type)
|
||||
}
|
||||
|
||||
public fun Int.assertType(changeType: SidesState) {
|
||||
fun Int.assertType(changeType: SidesState) {
|
||||
assertTrue(changeType != NONE)
|
||||
val change = change(this)
|
||||
val actual = change.type
|
||||
@@ -296,31 +296,31 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
assertEquals(Pair(isLeftChange, isRightChange), Pair(actual.isLeftChange, actual.isRightChange))
|
||||
}
|
||||
|
||||
public fun Int.assertResolved(type: SidesState) {
|
||||
fun Int.assertResolved(type: SidesState) {
|
||||
val change = change(this)
|
||||
val isLeftResolved = type == LEFT || type == BOTH
|
||||
val isRightResolved = type == RIGHT || type == BOTH
|
||||
assertEquals(Pair(isLeftResolved, isRightResolved), Pair(change.isResolved(Side.LEFT), change.isResolved(Side.RIGHT)))
|
||||
}
|
||||
|
||||
public fun Int.assertRange(start: Int, end: Int) {
|
||||
fun Int.assertRange(start: Int, end: Int) {
|
||||
val change = change(this)
|
||||
assertEquals(Pair(start, end), Pair(change.getStartLine(ThreeSide.BASE), change.getEndLine(ThreeSide.BASE)))
|
||||
}
|
||||
|
||||
public fun Int.assertContent(expected: String, start: Int, end: Int) {
|
||||
fun Int.assertContent(expected: String, start: Int, end: Int) {
|
||||
assertContent(expected)
|
||||
assertRange(start, end)
|
||||
}
|
||||
|
||||
public fun Int.assertContent(expected: String) {
|
||||
fun Int.assertContent(expected: String) {
|
||||
val change = change(this)
|
||||
val document = editor.document
|
||||
val actual = DiffUtil.getLinesContent(document, change.getStartLine(ThreeSide.BASE), change.getEndLine(ThreeSide.BASE))
|
||||
assertEquals(parseSource(expected), actual)
|
||||
}
|
||||
|
||||
public fun assertContent(expected: String) {
|
||||
fun assertContent(expected: String) {
|
||||
val actual = viewer.getEditor(ThreeSide.BASE).document.charsSequence
|
||||
assertEquals(parseSource(expected), actual)
|
||||
}
|
||||
@@ -329,14 +329,14 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
// Helpers
|
||||
//
|
||||
|
||||
public operator fun Int.not(): LineColHelper = LineColHelper(this)
|
||||
public operator fun LineColHelper.minus(col: Int): LineCol = LineCol(this.line, col)
|
||||
operator fun Int.not(): LineColHelper = LineColHelper(this)
|
||||
operator fun LineColHelper.minus(col: Int): LineCol = LineCol(this.line, col)
|
||||
|
||||
public inner class LineColHelper(val line: Int) {
|
||||
inner class LineColHelper(val line: Int) {
|
||||
}
|
||||
|
||||
public inner class LineCol(val line: Int, val col: Int) {
|
||||
public fun toOffset(): Int = editor.document.getLineStartOffset(line) + col
|
||||
inner class LineCol(val line: Int, val col: Int) {
|
||||
fun toOffset(): Int = editor.document.getLineStartOffset(line) + col
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,14 +368,14 @@ public abstract class MergeTestBase : DiffTestCase() {
|
||||
override fun getContentTitles(): List<String?> = listOf(null, null, null)
|
||||
}
|
||||
|
||||
public enum class SidesState {
|
||||
enum class SidesState {
|
||||
LEFT, RIGHT, BOTH, NONE
|
||||
}
|
||||
|
||||
private data class ViewerState private constructor(private val content: CharSequence,
|
||||
private val changes: List<ViewerState.ChangeState>) {
|
||||
companion object {
|
||||
public fun recordState(viewer: MyThreesideViewer): ViewerState {
|
||||
fun recordState(viewer: MyThreesideViewer): ViewerState {
|
||||
val content = viewer.getEditor(ThreeSide.BASE).document.getImmutableCharSequence()
|
||||
val changes = viewer.getAllChanges().map { recordChangeState(viewer, it) }
|
||||
return ViewerState(content, changes)
|
||||
|
||||
+13
-13
@@ -18,8 +18,8 @@ package com.intellij.diff.tools.fragmented
|
||||
import com.intellij.diff.util.Side
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
|
||||
public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
public fun testUnmodified() {
|
||||
class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
fun testUnmodified() {
|
||||
doTest(
|
||||
{
|
||||
equal(0, 0, 10, Side.LEFT)
|
||||
@@ -32,7 +32,7 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testEqual1() {
|
||||
fun testEqual1() {
|
||||
doTest(
|
||||
{
|
||||
equal(0, 0, 10, Side.LEFT)
|
||||
@@ -47,7 +47,7 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testEqual2() {
|
||||
fun testEqual2() {
|
||||
doTest(
|
||||
{
|
||||
equal(0, 0, 10, Side.LEFT)
|
||||
@@ -62,7 +62,7 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testEqual3() {
|
||||
fun testEqual3() {
|
||||
doTest(
|
||||
{
|
||||
equal(0, 0, 10, Side.LEFT)
|
||||
@@ -77,7 +77,7 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testEqual4() {
|
||||
fun testEqual4() {
|
||||
doTest(
|
||||
{
|
||||
equal(0, 0, 15, Side.LEFT)
|
||||
@@ -96,7 +96,7 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testInsideModifiedRange() {
|
||||
fun testInsideModifiedRange() {
|
||||
doTest(
|
||||
{
|
||||
equal(0, 0, 15, Side.LEFT)
|
||||
@@ -128,7 +128,7 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
private val builder = LineNumberConvertor.Builder()
|
||||
private var maxLength = 0 // search for strict matchings in this boundaries (*2 - just in case)
|
||||
|
||||
public fun equal(onesideStart: Int, twosideStart: Int, length: Int, side: Side) {
|
||||
fun equal(onesideStart: Int, twosideStart: Int, length: Int, side: Side) {
|
||||
if (side.isLeft) {
|
||||
builder.put1(onesideStart, twosideStart, length)
|
||||
}
|
||||
@@ -139,16 +139,16 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
maxLength = Math.max(maxLength, twosideStart + length)
|
||||
}
|
||||
|
||||
public fun finish(): Test = Test(builder.build(), maxLength)
|
||||
fun finish(): Test = Test(builder.build(), maxLength)
|
||||
}
|
||||
|
||||
private class Test(val convertor: LineNumberConvertor, var length: Int) {
|
||||
public fun change(onesideLine: Int, oldLength: Int, newLength: Int, side: Side) {
|
||||
fun change(onesideLine: Int, oldLength: Int, newLength: Int, side: Side) {
|
||||
convertor.handleOnesideChange(onesideLine, onesideLine + oldLength, newLength - oldLength, side)
|
||||
length = Math.max(length, length + newLength - oldLength)
|
||||
}
|
||||
|
||||
public fun checkStrictSymmetrical() {
|
||||
fun checkStrictSymmetrical() {
|
||||
for (i in 0..length * 2) {
|
||||
val value1 = convertor.convertInv1(i)
|
||||
if (value1 != -1) assertEquals(i, convertor.convert1(value1))
|
||||
@@ -164,7 +164,7 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun ensureMatchedCount(minimumMatched1: Int, minimumMatched2: Int) {
|
||||
fun ensureMatchedCount(minimumMatched1: Int, minimumMatched2: Int) {
|
||||
var counter1 = 0
|
||||
var counter2 = 0
|
||||
for (i in 0..length * 2) {
|
||||
@@ -175,7 +175,7 @@ public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
assertEquals(minimumMatched2, counter2)
|
||||
}
|
||||
|
||||
public fun printMatchings() {
|
||||
fun printMatchings() {
|
||||
for (i in 0..length * 2 - 1) {
|
||||
val value = convertor.convert1(i)
|
||||
if (value != -1) println("L: $i - $value")
|
||||
|
||||
+12
-12
@@ -17,8 +17,8 @@ package com.intellij.diff.tools.fragmented
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
|
||||
public class LineNumberConvertorTest : UsefulTestCase() {
|
||||
public fun testEmpty() {
|
||||
class LineNumberConvertorTest : UsefulTestCase() {
|
||||
fun testEmpty() {
|
||||
doTest(
|
||||
{
|
||||
},
|
||||
@@ -29,7 +29,7 @@ public class LineNumberConvertorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testSingleRange() {
|
||||
fun testSingleRange() {
|
||||
doTest(
|
||||
{
|
||||
put(2, 3, 2)
|
||||
@@ -46,7 +46,7 @@ public class LineNumberConvertorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testTwoRanges() {
|
||||
fun testTwoRanges() {
|
||||
doTest(
|
||||
{
|
||||
put(2, 3, 2)
|
||||
@@ -67,7 +67,7 @@ public class LineNumberConvertorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testAdjustmentRanges() {
|
||||
fun testAdjustmentRanges() {
|
||||
doTest(
|
||||
{
|
||||
put(2, 3, 2)
|
||||
@@ -85,7 +85,7 @@ public class LineNumberConvertorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testPartiallyAdjustmentRanges() {
|
||||
fun testPartiallyAdjustmentRanges() {
|
||||
doTest(
|
||||
{
|
||||
put(2, 3, 2)
|
||||
@@ -105,7 +105,7 @@ public class LineNumberConvertorTest : UsefulTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun testTwoRangesApproximate() {
|
||||
fun testTwoRangesApproximate() {
|
||||
doTest(
|
||||
{
|
||||
put(1, 2, 1)
|
||||
@@ -140,28 +140,28 @@ public class LineNumberConvertorTest : UsefulTestCase() {
|
||||
private class TestBuilder {
|
||||
private val builder = LineNumberConvertor.Builder()
|
||||
|
||||
public fun put(left: Int, right: Int, length: Int) {
|
||||
fun put(left: Int, right: Int, length: Int) {
|
||||
builder.put1(left, right, length)
|
||||
}
|
||||
|
||||
public fun finish(): Test = Test(builder.build())
|
||||
fun finish(): Test = Test(builder.build())
|
||||
}
|
||||
|
||||
private class Test(val convertor: LineNumberConvertor) {
|
||||
public fun checkMatch(left: Int, right: Int, length: Int) {
|
||||
fun checkMatch(left: Int, right: Int, length: Int) {
|
||||
for (i in 0..length - 1) {
|
||||
assertEquals(right + i, convertor.convert1(left + i))
|
||||
assertEquals(left + i, convertor.convertInv1(right + i))
|
||||
}
|
||||
}
|
||||
|
||||
public fun checkEmpty(start: Int, end: Int) {
|
||||
fun checkEmpty(start: Int, end: Int) {
|
||||
for (i in start..end) {
|
||||
assertEquals(-1, convertor.convert1(i))
|
||||
}
|
||||
}
|
||||
|
||||
public fun checkEmptyInv(start: Int, end: Int) {
|
||||
fun checkEmptyInv(start: Int, end: Int) {
|
||||
for (i in start..end) {
|
||||
assertEquals(-1, convertor.convertInv1(i))
|
||||
}
|
||||
|
||||
+4
-4
@@ -24,12 +24,12 @@ import com.intellij.openapi.editor.impl.DocumentImpl
|
||||
import com.intellij.openapi.progress.DumbProgressIndicator
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
public class UnifiedFragmentBuilderAutoTest : DiffTestCase() {
|
||||
public fun test() {
|
||||
class UnifiedFragmentBuilderAutoTest : DiffTestCase() {
|
||||
fun test() {
|
||||
doTest(System.currentTimeMillis(), 30, 30)
|
||||
}
|
||||
|
||||
public fun doTest(seed: Long, runs: Int, maxLength: Int) {
|
||||
fun doTest(seed: Long, runs: Int, maxLength: Int) {
|
||||
doAutoTest(seed, runs) { debugData ->
|
||||
debugData.put("MaxLength", maxLength)
|
||||
|
||||
@@ -49,7 +49,7 @@ public class UnifiedFragmentBuilderAutoTest : DiffTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun doTest(document1: Document, document2: Document, policy: ComparisonPolicy, masterSide: Side) {
|
||||
fun doTest(document1: Document, document2: Document, policy: ComparisonPolicy, masterSide: Side) {
|
||||
val sequence1 = document1.charsSequence
|
||||
val sequence2 = document2.charsSequence
|
||||
|
||||
|
||||
+3
-3
@@ -23,8 +23,8 @@ import com.intellij.openapi.editor.impl.DocumentImpl
|
||||
import com.intellij.openapi.progress.DumbProgressIndicator
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
|
||||
public class UnifiedFragmentBuilderTest : UsefulTestCase() {
|
||||
public fun testEquals() {
|
||||
class UnifiedFragmentBuilderTest : UsefulTestCase() {
|
||||
fun testEquals() {
|
||||
val document1 = DocumentImpl("A\nB\nC")
|
||||
val document2 = DocumentImpl("A\nB\nC")
|
||||
|
||||
@@ -39,7 +39,7 @@ public class UnifiedFragmentBuilderTest : UsefulTestCase() {
|
||||
assertEmpty(builder.blocks)
|
||||
}
|
||||
|
||||
public fun testWrongEndLineTypoBug() {
|
||||
fun testWrongEndLineTypoBug() {
|
||||
val document1 = DocumentImpl("A\nB\nC\nD")
|
||||
val document2 = DocumentImpl("A\nD")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user