|
| 1 | +package dotty.tools.dotc.printing |
| 2 | + |
| 3 | +import org.junit.Assert._ |
| 4 | +import org.junit.Test |
| 5 | + |
| 6 | +/** Adapted from Ammonite HighlightTests |
| 7 | + */ |
| 8 | +class SyntaxHighlightingTests { |
| 9 | + import SyntaxHighlighting._ |
| 10 | + |
| 11 | + private def test(source: String, expected: String): Unit = { |
| 12 | + val highlighted = SyntaxHighlighting.apply(source) |
| 13 | + .mkString |
| 14 | + .replace(NoColor, ">") |
| 15 | + .replace(CommentColor, "<C|") |
| 16 | + .replace(KeywordColor, "<K|") |
| 17 | + .replace(ValDefColor, "<V|") |
| 18 | + .replace(LiteralColor, "<L|") |
| 19 | + .replace(StringColor, "<S|") |
| 20 | + .replace(TypeColor, "<T|") |
| 21 | + // .replace(AnnotationColor, "<A|") // is the same color as type color |
| 22 | + |
| 23 | + if (expected != highlighted) { |
| 24 | + // assertEquals produces weird expected/found message |
| 25 | + fail(s"expected: $expected but was: $highlighted") |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + def comments = { |
| 31 | + test("//a", "<C|//a>") |
| 32 | + test("/** a */", "<C|/** a */>") |
| 33 | + test("/* a */", "<C|/* a */>") |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + def types = { |
| 38 | + test("type Foo = Int", "<K|type> <T|Foo> = <T|Int>") |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + def literals = { |
| 43 | + test("1", "<L|1>") |
| 44 | + // test("1L", "<L|1L>") |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + def strings = { |
| 49 | + // For some reason we currently use literal color for string |
| 50 | + test("\"Hello\"", "<L|\"Hello\">") |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + def annotations = { |
| 55 | + test("@tailrec", "<T|@tailrec>") |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + def expressions = { |
| 60 | + test("val x = 1 + 2 + 3", "<K|val> <V|x> = <L|1> + <L|2> + <L|3>") |
| 61 | + } |
| 62 | +} |
0 commit comments