private DiffSet FindAttributes(IList <int> notified, bool invert, DiffType diffType) { var builder = new DiffSetBuilder(); var mask = new List <int>(); var source = invert ? expected : actual; var pool = invert ? actual : expected; for (int i = 0; i < source.Count; i++) { int j = Find(pool, source[i], mask); if (j < 0) { var targets = invert ? DiffTargets.Expected : DiffTargets.Actual; builder.Add(new Diff(diffType, (invert ? pathExpected : path).Attribute(i), targets)); } else { int k = invert ? j : i; DiffSet diffSet = actual[k].Diff(expected[invert ? i : j], path, pathExpected, options); if (!diffSet.IsEmpty && !notified.Contains(k)) { builder.Add(diffSet); notified.Add(k); } mask.Add(j); } } return(builder.ToDiffSet()); }
/// <inheritdoc /> public DiffSet Diff() { var builder = new DiffSetBuilder(); int i = 0; while (i < expected.Count) { if (i >= actual.Count) { builder.Add(new Diff(itemType.DiffTypeMissing, itemType.ExtendsPath(pathExpected, i), DiffTargets.Expected)); } else { DiffSet diffSet = actual[i].Diff(expected[i], path, pathExpected, options); builder.Add(diffSet); if (!diffSet.IsEmpty && !actual[i].AreNamesEqual(expected[i].Name, options)) { return(builder.ToDiffSet()); } } i++; } return(builder .Add(ProcessExcessAttributes(i)) .ToDiffSet()); }
private DiffSet ProcessExcessAttributes(int startIndex) { var builder = new DiffSetBuilder(); for (int i = startIndex; i < actual.Count; i++) { builder.Add(new Diff(itemType.DiffTypeUnexpected, itemType.ExtendsPath(path, i), DiffTargets.Actual)); } return(builder.ToDiffSet()); }
private DiffSet FindElements(IList <int> notified, bool invert, DiffType diffType) { var builder = new DiffSetBuilder(); var mask = new List <int>(); var noExactMatch = new List <int>(); var source = invert ? expected : actual; var pool = invert ? actual : expected; // Find first exact match (= empty diff) for (int i = 0; i < source.Count; i++) { int j = pool.FindIndex(x => !mask.Contains(x) && source[i].Diff(pool[x], XmlPathRoot.Strict.Empty, XmlPathRoot.Strict.Empty, options).IsEmpty); if (j < 0) { noExactMatch.Add(i); } else { mask.Add(j); } } // Find first name-only match for the remaining items without exact match. foreach (int i in noExactMatch) { int j = pool.FindIndex(x => !mask.Contains(x) && source[i].AreNamesEqual(pool[x].Name, options)); if (j < 0) { builder.Add(new Diff(diffType, (invert ? pathExpected : path).Element(i), invert ? DiffTargets.Expected : DiffTargets.Actual)); } else { int k = invert ? j : i; DiffSet diffSet = actual[k].Diff(expected[invert ? i : j], path, pathExpected, options); if (!diffSet.IsEmpty && !notified.Contains(k)) { builder.Add(diffSet); notified.Add(k); } mask.Add(j); } } return(builder.ToDiffSet()); }