protected void HasDiagnostics(ProcessedCode processed, string diagnosticId)
        {
            var document = processed.Document;
            var spans    = processed.Spans;

            Assert.That(spans.Count, Is.GreaterThan(0), "At least one marker '[| |]' should be provided.");

            var diagnostics = GetDiagnostics(document);

            Console.WriteLine($"Got {diagnostics.Length} diagnostics:");
            Console.WriteLine(string.Join("\r\n", diagnostics));

            string expected = processed.GetCodeWithMarkers(diagnostics.Select(d => d.Location.SourceSpan).ToList());

            var message = $"Expected {spans.Count} diagnostic(s). Document with diagnostics:\r\n{expected}";

            Assert.That(diagnostics.Length, Is.EqualTo(spans.Count), message);

            var spanSet = new HashSet <TextSpan>(spans);

            foreach (var diagnostic in diagnostics)
            {
                Assert.That(diagnostic.Id, Is.EqualTo(diagnosticId));
                Assert.IsTrue(diagnostic.Location.IsInSource);
                Assert.IsTrue(spanSet.Contains(diagnostic.Location.SourceSpan), $"Can't find expected span. Expected:\r\n{expected}");
            }
        }
        protected void NoDiagnostic(
            Document document, string diagnosticId, ProcessedCode processedDocument)
        {
            var diagnostics = GetDiagnostics(document);

            string diagnosticMessage = string.Join("\r\n", diagnostics.Select(d => d.ToString()));

            Assert.That(diagnostics.Count(d => d.Id == diagnosticId),
                        Is.EqualTo(0), $"Expected no diagnostics, but got some:\r\n{diagnosticMessage}");
        }
        protected void HasDiagnostics(ProcessedCode processed, string diagnosticId)
        {
            var document = processed.Document;
            var spans    = processed.Spans;

            var    diagnostics = GetDiagnostics(document);
            string expected    = processed.GetCodeWithMarkers(diagnostics.Select(d => d.Location.SourceSpan).ToList());

            var message = $"Expected {spans.Count} diagnostic(s). Document with diagnostics:\r\n{expected}";

            Assert.That(diagnostics.Length, Is.EqualTo(spans.Count), message);

            var spanSet = new HashSet <TextSpan>(spans);

            foreach (var diagnostic in diagnostics)
            {
                Assert.That(diagnostic.Id, Is.EqualTo(diagnosticId));
                Assert.IsTrue(diagnostic.Location.IsInSource);
                Assert.IsTrue(spanSet.Contains(diagnostic.Location.SourceSpan), $"{expected}");
            }
        }
예제 #4
0
 protected void HasDiagnostics(ProcessedCode processed, string diagnosticId)
 {
     HasDiagnostics(processed, new [] { diagnosticId });
 }