public void Calculates_LineAndCharacter_Correctly(int position, int expectedLine, int expectedCharacter) { var input = "One\nTwo\r\nThree"; var sourceText = new SourceText(input); var lineAndCharacter = sourceText.GetLineAndCharacterPosition(position); Assert.That(lineAndCharacter.Line, Is.EqualTo(expectedLine)); Assert.That(lineAndCharacter.Character, Is.EqualTo(expectedCharacter)); }
private static void PrintErrors(SourceText text, IEnumerable <Diagnostic> diagnostics) { foreach (var diagnostic in diagnostics) { var startPosition = text.GetLineAndCharacterPosition(diagnostic.Span.Start); var line = text.Lines[startPosition.Line]; var linePrefix = text.Substring(line.Start, startPosition.Character); var lineProblem = text.Substring(diagnostic.Span.Start, diagnostic.Span.Length); var lineSuffix = text.Substring(diagnostic.Span.End, line.Length - diagnostic.Span.End); Console.WriteLine(); WriteLineToConsole(ConsoleColor.Red, $"Line: {startPosition.Line + 1} Char: {startPosition.Character + 1} {diagnostic.Message}"); Console.Write(" "); Console.Write(linePrefix); WriteToConsole(ConsoleColor.DarkRed, lineProblem); Console.WriteLine(lineSuffix); } Console.WriteLine(); }