示例#1
0
 public void ContainsDocumentAndDiffs()
 {
     DiffSet diffSet = new DiffSet(new[] { new Diff(DiffKind.Change, new Range(0, 3), new Range(0, 3)) }, "abc", "def");
     Assert.AreEqual("abc", diffSet.LeftDocument);
     Assert.AreEqual("def", diffSet.RightDocument);
     Assert.AreElementsEqual(new[] { new Diff(DiffKind.Change, new Range(0, 3), new Range(0, 3)) }, diffSet.Diffs);
 }
示例#2
0
 internal static void VerifyDiffSetIsValid(DiffSet diffSet)
 {
     foreach (Diff diff in diffSet.Diffs)
     {
         if (diff.Kind == DiffKind.NoChange)
             Assert.AreEqual(
                 diff.LeftRange.SubstringOf(diffSet.LeftDocument),
                 diff.RightRange.SubstringOf(diffSet.RightDocument));
         else
             Assert.AreNotEqual(
                 diff.LeftRange.SubstringOf(diffSet.LeftDocument),
                 diff.RightRange.SubstringOf(diffSet.RightDocument));
     }
 }
示例#3
0
        public void WriteTo_LeftOnlyWithLimitedContext()
        {
            DiffSet diffSet = new DiffSet(new Diff[] { 
                new Diff(DiffKind.Change, new Range(0, 1), new Range(0, 1)), // change
                new Diff(DiffKind.NoChange, new Range(1, 20), new Range(1, 20)), // same
                new Diff(DiffKind.Change, new Range(21, 1), new Range(21, 0)), // deletion
                new Diff(DiffKind.NoChange, new Range(22, 20), new Range(21, 20)), // same
                new Diff(DiffKind.Change, new Range(42, 0), new Range(41, 1)), // addition
            }, "accccccccccccccccccccdeeeeeeeeeeeeeeeeeeee", "bcccccccccccccccccccceeeeeeeeeeeeeeeeeeeef");

            StructuredTextWriter writer = new StructuredTextWriter();
            diffSet.WriteTo(writer, DiffStyle.LeftOnly, 7);

            Assert.AreEqual(new StructuredText(new BodyTag()
            {
                Contents = {
                    new MarkerTag(Marker.DiffChange) { Contents = { new TextTag("a") } },
                    new TextTag("ccc"),
                    new MarkerTag(Marker.Ellipsis) { Contents = { new TextTag("...") } },
                    new TextTag("ccc"),
                    new MarkerTag(Marker.DiffDeletion) { Contents = { new TextTag("d") } },
                    new TextTag("eee"),
                    new MarkerTag(Marker.Ellipsis) { Contents = { new TextTag("...") } },
                    new TextTag("eee")
                }
            }), writer.ToStructuredText());
        }
示例#4
0
        public void WriteTo_RightOnlyStyle()
        {
            DiffSet diffSet = new DiffSet(new Diff[] { 
                new Diff(DiffKind.Change, new Range(0, 1), new Range(0, 1)), // change
                new Diff(DiffKind.NoChange, new Range(1, 1), new Range(1, 1)), // same
                new Diff(DiffKind.Change, new Range(2, 1), new Range(2, 0)), // deletion
                new Diff(DiffKind.NoChange, new Range(3, 1), new Range(2, 1)), // same
                new Diff(DiffKind.Change, new Range(4, 0), new Range(3, 1)), // addition
            }, "acde", "bcef");

            StructuredTextWriter writer = new StructuredTextWriter();
            diffSet.WriteTo(writer, DiffStyle.RightOnly);
            TestLog.WriteLine(writer);

            Assert.AreEqual(new StructuredText(new BodyTag()
            {
                Contents = {
                    new MarkerTag(Marker.DiffChange) { Contents = { new TextTag("b") } },
                    new TextTag("ce"),
                    new MarkerTag(Marker.DiffDeletion) { Contents = { new TextTag("f") } }
                }
            }), writer.ToStructuredText());
        }
示例#5
0
 public void WriteToThrowsWhenMaxContextLengthIsNegative()
 {
     DiffSet diffSet = new DiffSet(new Diff[] { }, "", "");
     StructuredTextWriter writer = new StructuredTextWriter();
     Assert.Throws<ArgumentOutOfRangeException>(() => diffSet.WriteTo(writer, DiffStyle.Interleaved, -1));
 }
示例#6
0
 public void WriteToThrowsWhenWriterIsNull()
 {
     DiffSet diffSet = new DiffSet(new Diff[] { }, "", "");
     Assert.Throws<ArgumentNullException>(() => diffSet.WriteTo(null));
 }