コード例 #1
0
        public void TwoAnnotationsDotted()
        {
            var src = new SourceFile("simple.txt",
                                     @"line 1
prev line
this is a line of text
next line
line between
line between2
next line2
some other line
last line");
            var diag = new Diagnostic
            {
                Severity    = Severity.Error,
                Code        = "E0001",
                Message     = "Some error message",
                Information =
                {
                    new SpannedDiagnosticInfo
                    {
                        Span     = new Span(src, new Position(line: 2, column: 10), 4),
                        Message  = "some annotation1",
                        Severity = Severity.Error,
                    },
                    new SpannedDiagnosticInfo
                    {
                        Span    = new Span(src, new Position(line: 7, column: 5), 5),
                        Message = "some annotation2",
                    },
                },
            };
            var result   = new StringWriter();
            var renderer = new TextDiagnosticRenderer(result);

            renderer.Render(diag);
            Assert.AreEqual(@"error[E0001]: Some error message
  ┌─ simple.txt:3:11
  │
2 │ prev line
3 │ this is a line of text
  │           ^^^^ some annotation1
4 │ next line
  │ ...
7 │ next line2
8 │ some other line
  │      ----- some annotation2
9 │ last line
  │
", result.ToString());
        }
コード例 #2
0
        public void BasicSingleAnnotation()
        {
            var src = new SourceFile("simple.txt",
                                     @"line 1
prev line
this is a line of text
next line
some other line");
            var diag = new Diagnostic
            {
                Severity    = Severity.Error,
                Code        = "E0001",
                Message     = "Some error message",
                Information =
                {
                    new SpannedDiagnosticInfo
                    {
                        Span     = new Span(src, new Position(line: 2, column: 10), 4),
                        Message  = "some annotation",
                        Severity = Severity.Error,
                    }
                },
            };
            var result   = new StringWriter();
            var renderer = new TextDiagnosticRenderer(result);

            renderer.Render(diag);
            Assert.AreEqual(@"error[E0001]: Some error message
  ┌─ simple.txt:3:11
  │
2 │ prev line
3 │ this is a line of text
  │           ^^^^ some annotation
4 │ next line
  │
", result.ToString());
        }