public void LocateOwnerReturnsNullIfNoSpanReturnsTrueForOwnsSpan() { // Arrange Block block = new Block(BlockType.Markup, new SyntaxTreeNode[] { new MarkupSpan(SourceLocation.Zero, "Foo "), new StatementBlock(new SyntaxTreeNode[] { new TransitionSpan(new SourceLocation(4, 0, 4), "@"), new CodeSpan(new SourceLocation(5, 0, 5), "bar"), }), new MarkupSpan(new SourceLocation(8,0,8), " Baz") }); TextChange change = new TextChange(128, 1, new StringTextBuffer("Foo @bar Baz"), 1, new StringTextBuffer("Foo @bor Baz")); // Act Span actual = block.LocateOwner(change); // Assert Assert.IsNull(actual); }
internal static bool TreesAreDifferent(Block leftTree, Block rightTree, IEnumerable<TextChange> changes, CancellationToken cancelToken) { // Apply all the pending changes to the original tree // PERF: If this becomes a bottleneck, we can probably do it the other way around, // i.e. visit the tree and find applicable changes for each node. foreach (TextChange change in changes) { cancelToken.ThrowIfCancellationRequested(); Span changeOwner = leftTree.LocateOwner(change); // Apply the change to the tree if (changeOwner == null) { return true; } EditResult result = changeOwner.EditHandler.ApplyChange(changeOwner, change, force: true); changeOwner.ReplaceWith(result.EditedSpan); } // Now compare the trees bool treesDifferent = !leftTree.EquivalentTo(rightTree); return treesDifferent; }
internal static bool TreesAreDifferent(Block leftTree, Block rightTree, TextChange[] changes) { // Apply all the pending changes to the original tree // PERF: If this becomes a bottleneck, we can probably do it the other way around, // i.e. visit the tree and find applicable changes for each node. foreach (TextChange change in changes) { Span changeOwner = leftTree.LocateOwner(change); // Apply the change to the tree if (changeOwner == null) { return true; } EditResult result = changeOwner.EditHandler.ApplyChange(changeOwner, change, force: true); changeOwner.ReplaceWith(result.EditedSpan); } // Now compare the trees bool treesDifferent = !leftTree.EquivalentTo(rightTree); #if DEBUG if (RazorDebugHelpers.OutputDebuggingEnabled) { Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "Processed {0} changes, trees were{1} different", changes.Length, treesDifferent ? String.Empty : " not")); } #endif return treesDifferent; }
private static bool TreesAreDifferent(Block leftTree, Block rightTree, TextChange change) { Span changeOwner = leftTree.LocateOwner(change); // Apply the change to the tree if (changeOwner == null) { return true; } changeOwner.ApplyChange(change, force: true); // Now compare the trees return !Equals(leftTree, rightTree); }