static void AddResults <T>(List <DiffPair <T> > list, Slice <T> slice, DiffAction action) { for (int i = 0; i < slice.Length; i++) { list.Add(new DiffPair <T>(action, slice[i])); } }
private static Dictionary <IndexedName, RealNode> ParseChilds(XElement elem, DiffAction defaultAction) { return(elem.Elements() .Select(x => Parse(x, defaultAction)) .GroupBy(x => x.Raw.Name) .Aggregate(Enumerable.Empty <KeyValuePair <IndexedName, RealNode> >(), ReduceGroup) .ToDictionary(x => x.Key, x => x.Value)); }
private static RealNode Parse(XElement elem, DiffAction defaultAction) { Dictionary<IndexedName, RealNode> childs = elem.HasElements ? ParseChilds(elem, defaultAction) : new Dictionary<IndexedName, RealNode>(); Dictionary<XName, XAttribute> attributes = elem.Attributes().ToDictionary(x => x.Name, x => x); return new RealNode(defaultAction, elem, GetTextValue(elem), attributes, childs); }
private static Dictionary<IndexedName, RealNode> ParseChilds(XElement elem, DiffAction defaultAction) { return elem.Elements() .Select(x => Parse(x, defaultAction)) .GroupBy(x => x.Raw.Name) .Aggregate(Enumerable.Empty<KeyValuePair<IndexedName, RealNode>>(), ReduceGroup) .ToDictionary(x => x.Key, x => x.Value); }
public DiffOperation(DiffAction action, int startInOld, int endInOld, int startInNew, int endInNew) { this.Action = action; this.StartInOld = startInOld; this.EndInOld = endInOld; this.StartInNew = startInNew; this.EndInNew = endInNew; }
public DiffOperation(DiffAction action, int startInOld, int endInOld, int startInNew, int endInNew) { Action = action; StartInOld = startInOld; EndInOld = endInOld; StartInNew = startInNew; EndInNew = endInNew; }
public RealNode(DiffAction defaultAction, XElement raw, string value, Dictionary <XName, XAttribute> attrs, Dictionary <IndexedName, RealNode> childs) { DefaultAction = defaultAction; Raw = raw; Value = value; Childs = childs; Attributes = attrs; }
private static RealNode Parse(XElement elem, DiffAction defaultAction) { Dictionary <IndexedName, RealNode> childs = elem.HasElements ? ParseChilds(elem, defaultAction) : new Dictionary <IndexedName, RealNode>(); Dictionary <XName, XAttribute> attributes = elem.Attributes().ToDictionary(x => x.Name, x => x); return(new RealNode(defaultAction, elem, GetTextValue(elem), attributes, childs)); }
public DiffValue(DiffAction action, string raw) { if (string.IsNullOrEmpty(raw)) { throw new ArgumentNullException(nameof(raw)); } Action = action; Raw = raw; }
public void HandleAttr(XName attr, DiffAction diffAction) { if (diffAction == DiffAction.Added) { SetAttrs.Add(attr); } else if (diffAction == DiffAction.Removed) { RemoveAttrs.Add(attr); } }
private List <DiffOperation> Operations() { int startInOld = 0; int startInNew = 0; List <DiffOperation> list = new List <DiffOperation>(); List <DiffMatch> list2 = MatchingBlocks(); list2.Add(new DiffMatch(oldWords.Length, newWords.Length, 0)); for (int i = 0; i < list2.Count; i++) { DiffMatch match = list2[i]; bool flag = startInOld == match.StartInOld; bool flag2 = startInNew == match.StartInNew; DiffAction none = DiffAction.none; if (!flag && !flag2) { none = DiffAction.replace; } else if (flag && !flag2) { none = DiffAction.insert; } else if (!flag) { none = DiffAction.delete; } else { none = DiffAction.none; } if (none != DiffAction.none) { list.Add(new DiffOperation(none, startInOld, match.StartInOld, startInNew, match.StartInNew)); } if (match.Size != 0) { list.Add(new DiffOperation(DiffAction.equal, match.StartInOld, match.EndInOld, match.StartInNew, match.EndInNew)); } startInOld = match.EndInOld; startInNew = match.EndInNew; } return(list); }
private void verifyAttribute(DiffAction action, IEnumerable <DiffAttribute> attrs, XAttribute expected) { var raws = attrs.Where(x => x.Action == action).Select(x => x.Raw); Assert.IsTrue(raws.Any(x => x.Name == expected.Name && x.Value == expected.Value)); }
public DiffOperation(DiffAction action, int startInOld, int endInOld, int startInNew, int endInNew) { this.Action = action; this.StartInOld = startInOld; this.EndInOld = endInOld; this.StartInNew = startInNew; this.EndInNew = endInNew; }
private static void RunDiffTool(string createdFilePath, string referenceFilePath) { DiffAction?.ExecuteDiffAction(createdFilePath, referenceFilePath); }
private void ComputeChangeRecords() { while (true) { // first check end-of-lists termination cases... if (_newNodes.Count == 0) { // remaining old nodes are deleted if (_oldNodes.Count > 0) { RecordDeleteOld(_oldNodes.Count); } break; } else if (_oldNodes.Count == 0) { // remaining nodes were inserted if (_newNodes.Count > 0) { RecordInsertNew(_newNodes.Count); } break; } else { DiffAction action = GetNextAction(); switch (action.Operation) { case DiffOp.SkipBoth: RemoveFirst(_oldNodes, action.Count); RemoveFirst(_newNodes, action.Count); break; case DiffOp.ReduceOld: ReplaceFirstWithChildren(_oldNodes); break; case DiffOp.ReduceNew: ReplaceFirstWithChildren(_newNodes); break; case DiffOp.ReduceBoth: ReplaceFirstWithChildren(_oldNodes); ReplaceFirstWithChildren(_newNodes); break; case DiffOp.InsertNew: RecordInsertNew(action.Count); break; case DiffOp.DeleteOld: RecordDeleteOld(action.Count); break; case DiffOp.ReplaceOldWithNew: RecordReplaceOldWithNew(action.Count, action.Count); break; } } } }
public void IsChangedProperty_ShouldBeTrueIfDiffActionSpecified(DiffAction action) { var diffNode = new DiffNode(action, new XElement("some")); Assert.IsTrue(diffNode.IsChanged); }
public DiffAttribute(DiffAction action, XAttribute raw) { Action = action; Raw = raw ?? throw new ArgumentNullException(nameof(raw)); }
private List <DiffOperation> Operations() { int positionInOld = 0, positionInNew = 0; List <DiffOperation> operations = new List <DiffOperation>(); var matches = this.MatchingBlocks(); matches.Add(new DiffMatch(this.oldWords.Length, this.newWords.Length, 0)); for (int i = 0; i < matches.Count; i++) { var match = matches[i]; bool matchStartsAtCurrentPositionInOld = (positionInOld == match.StartInOld); bool matchStartsAtCurrentPositionInNew = (positionInNew == match.StartInNew); DiffAction action = DiffAction.none; if (matchStartsAtCurrentPositionInOld == false && matchStartsAtCurrentPositionInNew == false) { action = DiffAction.replace; } else if (matchStartsAtCurrentPositionInOld == true && matchStartsAtCurrentPositionInNew == false) { action = DiffAction.insert; } else if (matchStartsAtCurrentPositionInOld == false && matchStartsAtCurrentPositionInNew == true) { action = DiffAction.delete; } else // This occurs if the first few words are the same in both versions { action = DiffAction.none; } if (action != DiffAction.none) { operations.Add( new DiffOperation(action, positionInOld, match.StartInOld, positionInNew, match.StartInNew)); } if (match.Size != 0) { operations.Add(new DiffOperation( DiffAction.equal, match.StartInOld, match.EndInOld, match.StartInNew, match.EndInNew)); } positionInOld = match.EndInOld; positionInNew = match.EndInNew; } return(operations); }
public DiffPair(DiffAction action, T value) { this.Action = action; this.Value = value; }
public void IsChangedProperty_ShouldAlwaysBeTrue(DiffAction action) { var diffVal = new DiffValue(action, Raw); Assert.IsTrue(diffVal.IsChanged); }
public DiffPair(DiffAction action, T value) { Action = action; Value = value; }
public DiffNode(DiffAction action, XElement raw) : this(raw, null) { DiffAction = action; }
private void verifyText(DiffAction action, IEnumerable <DiffValue> texts, string expected) { var raws = texts.Where(x => x.Action == action).Select(x => x.Raw); Assert.IsTrue(raws.Any(x => x == expected)); }
public Pair(T source, DiffAction sourceAction, T result, DiffAction resultAction) : this(source, result) { SourceAction = sourceAction; ResultAction = resultAction; }
private static void _AddResults <T>(List <DiffPair <T> > list, Slice <T> slice, DiffAction action) { list.AddRange(slice.Select(t => new DiffPair <T>(action, t))); }