public void ProgramWithLinesTests()
        {
            // Arrange
            var programWithLines = new ProgramWithLines(@"line1
line2

line4
line5".CleanCR());

            // Act

            // Assert
            programWithLines.GetLine(0).Should().Be("line1");
            programWithLines.GetLine(1).Should().Be("line2");
            programWithLines.GetLine(3).Should().Be("line4");
            programWithLines.GetLine(4).Should().Be("line5");
            programWithLines.GetLineNumber(3).Should().Be(0);
            programWithLines.GetLineNumber(7).Should().Be(1);
            programWithLines.GetLineNumber(100).Should().Be(4);
            programWithLines.GetColumnNumber(2).Should().Be(2);
            programWithLines.GetColumnNumber(7).Should().Be(1);
            programWithLines.GetColumnNumber(9).Should().Be(3);
            programWithLines.GetHighlights(1, 3).Should().BeEquivalentTo(new List <Highlight> {
                new Highlight(0, "line1", 1, 3)
            });
            programWithLines.GetHighlights(2, 20).Should().BeEquivalentTo(new List <Highlight> {
                new Highlight(0, "line1", 2, 5),
                new Highlight(1, "line2", 0, 5),
                new Highlight(2, "", 0, 0),
                new Highlight(3, "line4", 0, 5),
                new Highlight(4, "line5", 0, 1),
            });
        }
Example #2
0
        public static string Highlight(ProgramWithLines programWithLines, int startPosition, int endPosition)
        {
            var highlights = programWithLines.GetHighlights(startPosition, endPosition);
            var result     = new StringBuilder();

            foreach (var highlight in highlights.Where(h => h.ColumnEnd - h.ColumnStart > 0))
            {
                result.AppendLine($"Line {highlight.LineNumber + 1}: {highlight.Line}");
                result.AppendLine(
                    $"Line {highlight.LineNumber + 1}: {ColumnMarkers(highlight)}");
            }
            return(result.ToString());
        }