diff: cleanup tests
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Wed, 2 Sep 2015 12:11:10 +0000 (15:11 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Wed, 2 Sep 2015 13:18:23 +0000 (16:18 +0300)
platform/diff-impl/tests/com/intellij/diff/Assertions.kt [new file with mode: 0644]
platform/diff-impl/tests/com/intellij/diff/comparison/AutoTestCase.kt
platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilAutoTest.kt
platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilTestBase.kt
platform/diff-impl/tests/com/intellij/diff/comparison/WordComparisonUtilTest.kt
platform/diff-impl/tests/com/intellij/diff/tools/fragmented/LineNumberConvertorCorrectorTest.kt
platform/diff-impl/tests/com/intellij/diff/tools/fragmented/LineNumberConvertorTest.kt
platform/diff-impl/tests/com/intellij/diff/tools/fragmented/UnifiedFragmentBuilderAutoTest.kt
platform/diff-impl/tests/com/intellij/diff/tools/fragmented/UnifiedFragmentBuilderTest.kt

diff --git a/platform/diff-impl/tests/com/intellij/diff/Assertions.kt b/platform/diff-impl/tests/com/intellij/diff/Assertions.kt
new file mode 100644 (file)
index 0000000..9379774
--- /dev/null
@@ -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)
+}
index eb3704f7ec7f57d17f83d826c18ce45f700702f0..c668441b1e1b0db29d94b3da19f2eabb4492e964 100644 (file)
  */
 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()
index 429160191acdddbcb0d94c25b0539304c1837861..c5230067c55e998974d2bf8b6a5db6e557998840 100644 (file)
@@ -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
index 7e0176da2462ad4d2935c1357d2cb08588f6a752..c051fffda418aed29ba94d539a1d6b86b0eae66f 100644 (file)
@@ -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) {
index 920cc3bc20a4417c5823905af11593219210de30..cc679071f64f40bade31d2f2c7f6e1be1510e05d 100644 (file)
@@ -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()
     }
index 1f252993a096c6d6030e39851a829c30b0467f11..9e84b4f9846b872570b8190f9685f5e7e09c7c67 100644 (file)
@@ -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() {
index 957614e4e3e384d394fff59b7fe4506829f6d6c4..1f29c3fc41186cee3d61778b270e3e19c11754f9 100644 (file)
@@ -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() {
index c7baa1c1a1fb3caa6347e2b5ccedb6f14d26c185..97dd02f204216be0c495a171ef8a7fb62a851f99 100644 (file)
@@ -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() {
index ef08a714af7cc551802295911894aeea59ae24f2..e2fe7be5f8b66bf3dec10ea84774142bf388ec4b 100644 (file)
  */
 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() {