@@ -12,9 +12,7 @@ object DiffUtil {
12
12
private final val DELETION_COLOR = ANSI_RED
13
13
private final val ADDITION_COLOR = ANSI_GREEN
14
14
15
- def mkColoredCodeDiff (code : String , lastCode : String , printDiffDel : Boolean ): String = {
16
-
17
- @ tailrec def splitTokens (str : String , acc : List [String ] = Nil ): List [String ] = {
15
+ @ tailrec private def splitTokens (str : String , acc : List [String ] = Nil ): List [String ] = {
18
16
if (str == " " ) {
19
17
acc.reverse
20
18
} else {
@@ -33,6 +31,30 @@ object DiffUtil {
33
31
}
34
32
}
35
33
34
+
35
+ /** @return a tuple of the (found, expected) diffs as strings */
36
+ def mkColoredTypeDiff (found : String , expected : String ): (String , String ) = {
37
+ val foundTokens = splitTokens(found, Nil ).toArray
38
+ val expectedTokens = splitTokens(expected, Nil ).toArray
39
+
40
+ val diffExp = hirschberg(foundTokens, expectedTokens)
41
+ val diffAct = hirschberg(expectedTokens, foundTokens)
42
+
43
+ val exp = diffExp.collect {
44
+ case Unmodified (str) => str
45
+ case Inserted (str) => ADDITION_COLOR + str + ANSI_DEFAULT
46
+ }.mkString
47
+
48
+ val fnd = diffAct.collect {
49
+ case Unmodified (str) => str
50
+ case Inserted (str) => DELETION_COLOR + str + ANSI_DEFAULT
51
+ }.mkString
52
+
53
+ (fnd, exp)
54
+ }
55
+
56
+ def mkColoredCodeDiff (code : String , lastCode : String , printDiffDel : Boolean ): String = {
57
+
36
58
val tokens = splitTokens(code, Nil ).toArray
37
59
val lastTokens = splitTokens(lastCode, Nil ).toArray
38
60
0 commit comments