merge: cleanup tests

This commit is contained in:
Aleksey Pivovarov
2017-03-06 16:50:39 +03:00
committed by Aleksey Pivovarov
parent 929afafc64
commit e91402bb87
2 changed files with 92 additions and 90 deletions
@@ -18,7 +18,7 @@ package com.intellij.diff.merge
import com.intellij.diff.merge.MergeTestBase.SidesState.*
import com.intellij.diff.util.Side
import com.intellij.diff.util.TextDiffType.*
import com.intellij.idea.ActionsBundle
import com.intellij.diff.util.ThreeSide
class MergeTest : MergeTestBase() {
fun testChangeTypes() {
@@ -534,109 +534,105 @@ class MergeTest : MergeTestBase() {
}
fun testNonConflictsActions() {
val applyAllTitle = ActionsBundle.actionText("Diff.ApplyNonConflicts")
val applyLeftTitle = ActionsBundle.actionText("Diff.ApplyNonConflicts.Left")
val applyRightTitle = ActionsBundle.actionText("Diff.ApplyNonConflicts.Right")
val text1 =
"1 ======\n" +
"insert left\n" +
"2 ======\n" +
"remove right\n" +
"3 ======\n" +
"new both\n" +
"4 ======\n" +
"modify both\n" +
"5 ======\n" +
"modify\n" +
"6 ======\n" +
"7 ======"
val text2 =
"1 ======\n" +
"2 ======\n" +
"remove right\n" +
"3 ======\n" +
"4 ======\n" +
"modify\n" +
"5 ======\n" +
"modify\n" +
"6 ======\n" +
"delete modify\n" +
"7 ======"
val text3 =
"1 ======\n" +
"2 ======\n" +
"3 ======\n" +
"new both\n" +
"4 ======\n" +
"modify both\n" +
"5 ======\n" +
"modify right\n" +
"6 ======\n" +
"modify\n" +
"7 ======"
val text1 = """
1 ======
insert left
2 ======
remove right
3 ======
new both
4 ======
modify both
5 ======
modify
6 ======
7 ======""".trimIndent()
val text2 = """
1 ======
2 ======
remove right
3 ======
4 ======
modify
5 ======
modify
6 ======
delete modify
7 ======""".trimIndent()
val text3 = """
1 ======
2 ======
3 ======
new both
4 ======
modify both
5 ======
modify right
6 ======
modify
7 ======""".trimIndent()
testN(text1, text2, text3) {
checkUndo(1) {
runActionByTitle(applyAllTitle)
runApplyNonConflictsAction(ThreeSide.BASE)
}
assertChangesCount(1)
assertContent(
"1 ======\n" +
"insert left\n" +
"2 ======\n" +
"3 ======\n" +
"new both\n" +
"4 ======\n" +
"modify both\n" +
"5 ======\n" +
"modify right\n" +
"6 ======\n" +
"delete modify\n" +
"7 ======")
assertContent("""
1 ======
insert left
2 ======
3 ======
new both
4 ======
modify both
5 ======
modify right
6 ======
delete modify
7 ======""".trimIndent())
}
testN(text1, text2, text3) {
checkUndo(1) {
runActionByTitle(applyLeftTitle)
runApplyNonConflictsAction(ThreeSide.LEFT)
}
assertChangesCount(3)
assertContent(
"1 ======\n" +
"insert left\n" +
"2 ======\n" +
"remove right\n" +
"3 ======\n" +
"new both\n" +
"4 ======\n" +
"modify both\n" +
"5 ======\n" +
"modify\n" +
"6 ======\n" +
"delete modify\n" +
"7 ======")
assertContent("""
1 ======
insert left
2 ======
remove right
3 ======
new both
4 ======
modify both
5 ======
modify
6 ======
delete modify
7 ======""".trimIndent())
}
testN(text1, text2, text3) {
checkUndo(1) {
runActionByTitle(applyRightTitle)
runApplyNonConflictsAction(ThreeSide.RIGHT)
}
assertChangesCount(2)
assertContent(
"1 ======\n" +
"2 ======\n" +
"3 ======\n" +
"new both\n" +
"4 ======\n" +
"modify both\n" +
"5 ======\n" +
"modify right\n" +
"6 ======\n" +
"delete modify\n" +
"7 ======")
assertContent("""
1 ======
2 ======
3 ======
new both
4 ======
modify both
5 ======
modify right
6 ======
delete modify
7 ======""".trimIndent())
}
}
}
@@ -23,6 +23,8 @@ import com.intellij.diff.merge.TextMergeViewer.MyThreesideViewer
import com.intellij.diff.util.DiffUtil
import com.intellij.diff.util.Side
import com.intellij.diff.util.TextDiffType
import com.intellij.diff.util.ThreeSide
import com.intellij.idea.ActionsBundle
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -114,10 +116,14 @@ abstract class MergeTestBase : DiffTestCase() {
// Actions
//
fun runActionByTitle(name: String): Boolean {
val action = actions.filter { name == it.templatePresentation.text }
assertTrue(action.size == 1, action.toString())
return runAction(action[0])
fun runApplyNonConflictsAction(side: ThreeSide) {
runActionById(side.select("Diff.ApplyNonConflicts.Left", "Diff.ApplyNonConflicts", "Diff.ApplyNonConflicts.Right")!!)
}
private fun runActionById(id: String): Boolean {
val text = ActionsBundle.actionText(id)
val action = actions.filter { text == it.templatePresentation.text }.single()
return runAction(action)
}
private fun runAction(action: AnAction): Boolean {
@@ -378,8 +384,8 @@ abstract class MergeTestBase : DiffTestCase() {
LEFT, RIGHT, BOTH, NONE
}
private data class ViewerState private constructor(private val content: CharSequence,
private val changes: List<ViewerState.ChangeState>) {
private data class ViewerState constructor(private val content: CharSequence,
private val changes: List<ViewerState.ChangeState>) {
companion object {
fun recordState(viewer: MyThreesideViewer): ViewerState {
val content = viewer.editor.document.immutableCharSequence