diff --git a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index db8e30e4977e..a4f3d0a522ae 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -10,6 +10,7 @@ import util.Chars /** This object provides functions for syntax highlighting in the REPL */ object SyntaxHighlighting { + // Keep in sync with SyntaxHighlightingTests val NoColor = Console.RESET val CommentColor = Console.BLUE val KeywordColor = Console.YELLOW diff --git a/compiler/test/dotty/tools/dotc/reporting/SyntaxHighlightingTests.scala b/compiler/test/dotty/tools/dotc/reporting/SyntaxHighlightingTests.scala new file mode 100644 index 000000000000..35f81e43263e --- /dev/null +++ b/compiler/test/dotty/tools/dotc/reporting/SyntaxHighlightingTests.scala @@ -0,0 +1,62 @@ +package dotty.tools.dotc.printing + +import org.junit.Assert._ +import org.junit.Test + +/** Adapted from Ammonite HighlightTests + */ +class SyntaxHighlightingTests { + import SyntaxHighlighting._ + + private def test(source: String, expected: String): Unit = { + val highlighted = SyntaxHighlighting.apply(source) + .mkString + .replace(NoColor, ">") + .replace(CommentColor, "") + test("/** a */", "") + test("/* a */", "") + } + + @Test + def types = { + test("type Foo = Int", " = ") + } + + @Test + def literals = { + test("1", "") + // test("1L", "") + } + + @Test + def strings = { + // For some reason we currently use literal color for string + test("\"Hello\"", "") + } + + @Test + def annotations = { + test("@tailrec", "") + } + + @Test + def expressions = { + test("val x = 1 + 2 + 3", " = + + ") + } +}