|
| 1 | +package dotty.tools.dotc.util |
| 2 | + |
| 3 | +import org.junit.Assert._ |
| 4 | +import org.junit.Test |
| 5 | + |
| 6 | +class DiffUtilTests { |
| 7 | + |
| 8 | + def testExpected(found: String, expected: String, foundColoring: String, expectedColoring: String): Unit = { |
| 9 | + def humanAscii(str: String): String = |
| 10 | + str |
| 11 | + .replace(Console.RESET, ">") |
| 12 | + .replace(Console.BOLD, "") |
| 13 | + .replace(Console.RED, "<R|") |
| 14 | + .replace(Console.GREEN, "<G|") |
| 15 | + // merging two aligning colors |
| 16 | + .replace("><R|", "") |
| 17 | + .replace("><G|", "") |
| 18 | + |
| 19 | + val diff = DiffUtil.mkColoredTypeDiff(found, expected) |
| 20 | + val fnd = humanAscii(diff._1) |
| 21 | + val exp = humanAscii(diff._2) |
| 22 | + |
| 23 | + if (fnd != foundColoring) fail(s"expected(found):\n$foundColoring but was: \n$fnd") |
| 24 | + if (exp != expectedColoring) fail(s"expected(expected): \n$expectedColoring but was: \n$exp") |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + def simpleString(): Unit = { |
| 29 | + testExpected("Foo", "Bar", "<R|Foo>", "<G|Bar>") |
| 30 | + testExpected("Bar", "Foo", "<R|Bar>", "<G|Foo>") |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + def tuple(): Unit = { |
| 35 | + testExpected("(Foo, Bar)", "(Bar, Foo)", "(<R|Foo>, <R|Bar>)", "(<G|Bar>, <G|Foo>)") |
| 36 | + testExpected("(Int, Bar, Float)", "Bar", "<R|(Int, >Bar<R|, Float)>", "Bar") |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + def tupleSeq(): Unit = { |
| 41 | + testExpected("(Foo, Seq[Bar])", "Seq[Bar]", "<R|(Foo, >Seq[Bar]<R|)>", "Seq[Bar]") |
| 42 | + testExpected("Seq[Bar]", "(Foo, Seq[Bar])", "Seq[Bar]", "<G|(Foo, >Seq[Bar]<G|)>") |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + def seqTuple(): Unit = { |
| 47 | + testExpected("Seq[(Foo, Bar)]", "Seq[Bar]", "Seq[<R|(Foo, >Bar<R|)>]", "Seq[Bar]") |
| 48 | + testExpected("Seq[Bar]", "Seq[(Foo, Bar)]", "Seq[Bar]", "Seq[<G|(Foo, >Bar<G|)>]") |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + def seqSeq(): Unit = { |
| 53 | + testExpected("Seq[Seq[Seq[Foo]]]", "Seq[List[Seq[(Bar, Foo)]]]", "Seq[<R|Seq>[Seq[Foo]]]", "Seq[<G|List>[Seq[<G|(Bar, >Foo<G|)>]]]") |
| 54 | + testExpected("Seq[List[Seq[(Bar, Foo)]]]", "Seq[Seq[Seq[Foo]]]", "Seq[<R|List>[Seq[<R|(Bar, >Foo<R|)>]]]", "Seq[<G|Seq>[Seq[Foo]]]") |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments