mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: cleanup tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.diff
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import junit.framework.TestCase
|
||||
|
||||
public fun assertTrue(actual: Boolean, message: String = "") {
|
||||
TestCase.assertTrue(message, actual)
|
||||
}
|
||||
|
||||
public fun assertFalse(actual: Boolean, message: String = "") {
|
||||
TestCase.assertFalse(message, actual)
|
||||
}
|
||||
|
||||
public fun assertEquals(expected: Any?, actual: Any?, message: String = "") {
|
||||
TestCase.assertEquals(message, expected, actual)
|
||||
}
|
||||
|
||||
public fun assertEmpty(collection: Collection<*>, message: String = "") {
|
||||
UsefulTestCase.assertEmpty(message, collection)
|
||||
}
|
||||
|
||||
public fun assertOrderedEquals(expected: Collection<*>, actual: Collection<*>, message: String = "") {
|
||||
UsefulTestCase.assertOrderedEquals(message, actual, expected)
|
||||
}
|
||||
|
||||
public fun assertNull(actual: Any?, message: String = "") {
|
||||
TestCase.assertNull(message, actual)
|
||||
}
|
||||
|
||||
public fun assertNotNull(actual: Any?, message: String = "") {
|
||||
TestCase.assertNotNull(message, actual)
|
||||
}
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison
|
||||
|
||||
import com.intellij.diff.assertTrue
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.util.text.CharSequenceSubSequence
|
||||
import java.util.Random
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
public abstract class AutoTestCase : UsefulTestCase() {
|
||||
protected val RNG: Random = Random()
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison
|
||||
|
||||
import com.intellij.diff.assertEquals
|
||||
import com.intellij.diff.assertFalse
|
||||
import com.intellij.diff.assertTrue
|
||||
import com.intellij.diff.fragments.DiffFragment
|
||||
import com.intellij.diff.fragments.LineFragment
|
||||
import com.intellij.diff.util.DiffUtil
|
||||
@@ -26,9 +29,6 @@ import com.intellij.openapi.util.Ref
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.containers.HashMap
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
public class ComparisonUtilAutoTest : AutoTestCase() {
|
||||
private var oldRegistryValue: Boolean = false
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison
|
||||
|
||||
import com.intellij.diff.assertEquals
|
||||
import com.intellij.diff.assertOrderedEquals
|
||||
import com.intellij.diff.assertTrue
|
||||
import com.intellij.diff.fragments.DiffFragment
|
||||
import com.intellij.diff.fragments.LineFragment
|
||||
import com.intellij.openapi.editor.Document
|
||||
@@ -25,8 +28,6 @@ import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import java.util.BitSet
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
public abstract class ComparisonUtilTestBase : UsefulTestCase() {
|
||||
private var oldRegistryValue: Boolean = false
|
||||
@@ -46,10 +47,9 @@ public abstract class ComparisonUtilTestBase : UsefulTestCase() {
|
||||
// Impl
|
||||
//
|
||||
|
||||
private fun doLineTest(before: Document, after: Document, matchings: Couple<BitSet>?, expected: List<Change>?, policy: ComparisonPolicy) {
|
||||
private fun doLineTest(before: Document, after: Document, expected: List<Change>?, policy: ComparisonPolicy) {
|
||||
val fragments = MANAGER.compareLines(before.getCharsSequence(), after.getCharsSequence(), policy, INDICATOR)
|
||||
checkConsistency(fragments, before, after)
|
||||
if (matchings != null) checkLineMatching(fragments, matchings)
|
||||
if (expected != null) checkLineChanges(fragments, expected)
|
||||
}
|
||||
|
||||
@@ -70,10 +70,9 @@ public abstract class ComparisonUtilTestBase : UsefulTestCase() {
|
||||
if (expected != null) checkDiffChanges(fragments, expected)
|
||||
}
|
||||
|
||||
private fun doSplitterTest(before: Document, after: Document, matchings: Couple<BitSet>?, expected: List<Change>?, policy: ComparisonPolicy) {
|
||||
private fun doSplitterTest(before: Document, after: Document, expected: List<Change>?, policy: ComparisonPolicy) {
|
||||
val fragments = MANAGER.compareLinesInner(before.getCharsSequence(), after.getCharsSequence(), policy, INDICATOR)
|
||||
checkConsistency(fragments, before, after)
|
||||
if (matchings != null) checkLineMatching(fragments, matchings)
|
||||
if (expected != null) checkLineChanges(fragments, expected)
|
||||
}
|
||||
|
||||
@@ -119,24 +118,12 @@ public abstract class ComparisonUtilTestBase : UsefulTestCase() {
|
||||
|
||||
private fun checkLineChanges(fragments: List<LineFragment>, expected: List<Change>) {
|
||||
val changes = convertLineFragments(fragments)
|
||||
UsefulTestCase.assertOrderedEquals(changes, expected)
|
||||
assertOrderedEquals(changes, expected)
|
||||
}
|
||||
|
||||
private fun checkDiffChanges(fragments: List<DiffFragment>, expected: List<Change>) {
|
||||
val changes = convertDiffFragments(fragments)
|
||||
UsefulTestCase.assertOrderedEquals(changes, expected)
|
||||
}
|
||||
|
||||
private fun checkLineMatching(fragments: List<LineFragment>, matchings: Couple<BitSet>) {
|
||||
val set1 = BitSet()
|
||||
val set2 = BitSet()
|
||||
for (fragment in fragments) {
|
||||
set1.set(fragment.getStartLine1(), fragment.getEndLine1())
|
||||
set2.set(fragment.getStartLine2(), fragment.getEndLine2())
|
||||
}
|
||||
|
||||
assertEquals(matchings.first, set1)
|
||||
assertEquals(matchings.second, set2)
|
||||
assertOrderedEquals(changes, expected)
|
||||
}
|
||||
|
||||
private fun checkDiffMatching(fragments: List<DiffFragment>, matchings: Couple<BitSet>) {
|
||||
@@ -230,10 +217,10 @@ public abstract class ComparisonUtilTestBase : UsefulTestCase() {
|
||||
assertTrue(change != null || matchings != null)
|
||||
|
||||
when (type) {
|
||||
TestType.LINE -> doLineTest(before!!, after!!, matchings, change, policy)
|
||||
TestType.LINE -> doLineTest(before!!, after!!, change, policy)
|
||||
TestType.WORD -> doWordTest(before!!, after!!, matchings, change, policy)
|
||||
TestType.CHAR -> doCharTest(before!!, after!!, matchings, change, policy)
|
||||
TestType.SPLITTER -> doSplitterTest(before!!, after!!, matchings, change, policy)
|
||||
TestType.SPLITTER -> doSplitterTest(before!!, after!!, change, policy)
|
||||
}
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
|
||||
@@ -227,7 +227,7 @@ public class WordComparisonUtilTest : ComparisonUtilTestBase() {
|
||||
|
||||
words {
|
||||
("x .. z" - "x y .. z")
|
||||
(" " - " -- ").default() // TODO: looks wrong.default()
|
||||
(" " - " -- ").default() // TODO: looks wrong
|
||||
(" " - " - ").ignore()
|
||||
testAll()
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.intellij.diff.tools.fragmented
|
||||
|
||||
import com.intellij.diff.assertEquals
|
||||
import com.intellij.diff.util.Side
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
public class LineNumberConvertorCorrectorTest : UsefulTestCase() {
|
||||
public fun testUnmodified() {
|
||||
|
||||
+1
-1
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.diff.tools.fragmented
|
||||
|
||||
import com.intellij.diff.assertEquals
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
public class LineNumberConvertorTest : UsefulTestCase() {
|
||||
public fun testEmpty() {
|
||||
|
||||
+2
-2
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.diff.tools.fragmented
|
||||
|
||||
import com.intellij.diff.assertEquals
|
||||
import com.intellij.diff.assertTrue
|
||||
import com.intellij.diff.comparison.AutoTestCase
|
||||
import com.intellij.diff.comparison.ComparisonManagerImpl
|
||||
import com.intellij.diff.comparison.ComparisonPolicy
|
||||
@@ -25,8 +27,6 @@ import com.intellij.openapi.editor.impl.DocumentImpl
|
||||
import com.intellij.openapi.progress.DumbProgressIndicator
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.containers.HashMap
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
public class UnifiedFragmentBuilderAutoTest : AutoTestCase() {
|
||||
public fun test() {
|
||||
|
||||
+6
-5
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package com.intellij.diff.tools.fragmented
|
||||
|
||||
import com.intellij.diff.assertEmpty
|
||||
import com.intellij.diff.assertEquals
|
||||
import com.intellij.diff.assertFalse
|
||||
import com.intellij.diff.assertTrue
|
||||
import com.intellij.diff.comparison.ComparisonManagerImpl
|
||||
import com.intellij.diff.comparison.ComparisonPolicy
|
||||
import com.intellij.diff.util.LineRange
|
||||
@@ -22,9 +26,6 @@ import com.intellij.diff.util.Side
|
||||
import com.intellij.openapi.editor.impl.DocumentImpl
|
||||
import com.intellij.openapi.progress.DumbProgressIndicator
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
public class UnifiedFragmentBuilderTest : UsefulTestCase() {
|
||||
public fun testEquals() {
|
||||
@@ -38,8 +39,8 @@ public class UnifiedFragmentBuilderTest : UsefulTestCase() {
|
||||
|
||||
assertTrue(builder.isEqual())
|
||||
assertEquals(builder.getText().toString(), "A\nB\nC\n")
|
||||
UsefulTestCase.assertEmpty(builder.getChangedLines())
|
||||
UsefulTestCase.assertEmpty(builder.getBlocks())
|
||||
assertEmpty(builder.getChangedLines())
|
||||
assertEmpty(builder.getBlocks())
|
||||
}
|
||||
|
||||
public fun testWrongEndLineTypoBug() {
|
||||
|
||||
Reference in New Issue
Block a user