aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/util/DiffUtil.scala28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/util/DiffUtil.scala b/src/dotty/tools/dotc/util/DiffUtil.scala
index b7c77ad62..8bb39c88a 100644
--- a/src/dotty/tools/dotc/util/DiffUtil.scala
+++ b/src/dotty/tools/dotc/util/DiffUtil.scala
@@ -12,9 +12,7 @@ object DiffUtil {
private final val DELETION_COLOR = ANSI_RED
private final val ADDITION_COLOR = ANSI_GREEN
- def mkColoredCodeDiff(code: String, lastCode: String, printDiffDel: Boolean): String = {
-
- @tailrec def splitTokens(str: String, acc: List[String] = Nil): List[String] = {
+ @tailrec private def splitTokens(str: String, acc: List[String] = Nil): List[String] = {
if (str == "") {
acc.reverse
} else {
@@ -33,6 +31,30 @@ object DiffUtil {
}
}
+
+ /** @return a tuple of the (found, expected) diffs as strings */
+ def mkColoredTypeDiff(found: String, expected: String): (String, String) = {
+ val foundTokens = splitTokens(found, Nil).toArray
+ val expectedTokens = splitTokens(expected, Nil).toArray
+
+ val diffExp = hirschberg(foundTokens, expectedTokens)
+ val diffAct = hirschberg(expectedTokens, foundTokens)
+
+ val exp = diffExp.collect {
+ case Unmodified(str) => str
+ case Inserted(str) => ADDITION_COLOR + str + ANSI_DEFAULT
+ }.mkString
+
+ val fnd = diffAct.collect {
+ case Unmodified(str) => str
+ case Inserted(str) => DELETION_COLOR + str + ANSI_DEFAULT
+ }.mkString
+
+ (fnd, exp)
+ }
+
+ def mkColoredCodeDiff(code: String, lastCode: String, printDiffDel: Boolean): String = {
+
val tokens = splitTokens(code, Nil).toArray
val lastTokens = splitTokens(lastCode, Nil).toArray