private static void Verify(IEnumerable <Diagnostic> actual, DiagnosticDescription[] expected, bool errorCodeOnly) { if (expected == null) { throw new ArgumentException("Must specify expected errors.", nameof(expected)); } var unmatched = actual.Select(d => new DiagnosticDescription(d, errorCodeOnly)).ToList(); // Try to match each of the 'expected' errors to one of the 'actual' ones. // If any of the expected errors don't appear, fail test. foreach (var d in expected) { int index = unmatched.IndexOf(d); if (index > -1) { unmatched.RemoveAt(index); } else { Assert.True(false, DiagnosticDescription.GetAssertText(expected, actual)); } } // If any 'extra' errors appear that were not in the 'expected' list, fail test. if (unmatched.Count > 0) { Assert.True(false, DiagnosticDescription.GetAssertText(expected, actual)); } }
private static void Verify(IEnumerable <Diagnostic> actual, DiagnosticDescription[] expected, bool errorCodeOnly) { if (expected == null) { throw new ArgumentException("Must specify expected errors.", nameof(expected)); } var includeDefaultSeverity = expected.Any() && expected.All(e => e.DefaultSeverity != null); var includeEffectiveSeverity = expected.Any() && expected.All(e => e.EffectiveSeverity != null); var unmatchedActualDescription = actual.Select(d => new DiagnosticDescription(d, errorCodeOnly, includeDefaultSeverity, includeEffectiveSeverity)) .ToList(); var unmatchedActualIndex = actual.Select((_, i) => i).ToList(); var unmatchedExpected = ArrayBuilder <DiagnosticDescription> .GetInstance(); // Try to match each of the 'expected' errors to one of the 'actual' ones. // If any of the expected errors don't appear, fail test. foreach (var d in expected) { int index = unmatchedActualDescription.IndexOf(d); if (index > -1) { unmatchedActualDescription.RemoveAt(index); unmatchedActualIndex.RemoveAt(index); } else { unmatchedExpected.Add(d); } } if (unmatchedActualDescription.Count > 0 || unmatchedExpected.Count > 0) { Assert.True(false, DiagnosticDescription.GetAssertText(expected, actual, unmatchedExpected.ToArray(), actual.Select((a, i) => (a, i)).Join(unmatchedActualIndex, ai => ai.i, i => i, (ai, _) => ai.a))); } unmatchedExpected.Free(); }