Пример #1
0
        private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Location acturalLocation, DiagnosticResultLocation expectedLocation)
        {
            var actualSpan = acturalLocation.GetLineSpan();

            Assert.IsTrue(actualSpan.Path == expectedLocation.Path || (actualSpan.Path != null && actualSpan.Path.Contains("Test0.") && expectedLocation.Path.Contains("Test.")),
                          $"Expected diagnostic to be in file \"{expectedLocation.Path}\" was actually in file \"{actualSpan.Path}\"{NewLine}{NewLine}Diagnostic:{NewLine}    {FormatDiagnostics(analyzer, diagnostic)}{NewLine}");


            var actualLinePosition = actualSpan.StartLinePosition;

            if (actualLinePosition.Line > 0 && actualLinePosition.Line + 1 != expectedLocation.Line)
            {
                Assert.Fail($"Expected diagnostic to be on line \"{expectedLocation.Line}\" was actually on line \"{actualLinePosition.Line + 1}\"{NewLine}{NewLine}Diagnostic:{NewLine}    {FormatDiagnostics(analyzer, diagnostic)}{NewLine}");
            }
            if (actualLinePosition.Character > 0 && actualLinePosition.Character + 1 != expectedLocation.Column)
            {
                Assert.Fail($"Expected diagnostic to start at column \"{expectedLocation.Column}\" was actually at column \"{actualLinePosition.Character + 1}\"{NewLine}{NewLine}Diagnostic:{NewLine}    {FormatDiagnostics(analyzer, diagnostic)}{NewLine}");
            }
        }
Пример #2
0
		private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Location acturalLocation, DiagnosticResultLocation expectedLocation)
		{
			var actualSpan = acturalLocation.GetLineSpan();

			Assert.IsTrue(actualSpan.Path == expectedLocation.Path || (actualSpan.Path != null && actualSpan.Path.Contains("Test0.") && expectedLocation.Path.Contains("Test.")),
				$"Expected diagnostic to be in file \"{expectedLocation.Path}\" was actually in file \"{actualSpan.Path}\"{NewLine}{NewLine}Diagnostic:{NewLine}    {FormatDiagnostics(analyzer, diagnostic)}{NewLine}");


			var actualLinePosition = actualSpan.StartLinePosition;
			if (actualLinePosition.Line > 0 && actualLinePosition.Line + 1 != expectedLocation.Line)
			{
				Assert.Fail($"Expected diagnostic to be on line \"{expectedLocation.Line}\" was actually on line \"{actualLinePosition.Line + 1}\"{NewLine}{NewLine}Diagnostic:{NewLine}    {FormatDiagnostics(analyzer, diagnostic)}{NewLine}");
			}
			if (actualLinePosition.Character > 0 && actualLinePosition.Character + 1 != expectedLocation.Column)
			{
				Assert.Fail($"Expected diagnostic to start at column \"{expectedLocation.Column}\" was actually at column \"{actualLinePosition.Character + 1}\"{NewLine}{NewLine}Diagnostic:{NewLine}    {FormatDiagnostics(analyzer, diagnostic)}{NewLine}");
			}
		}