public virtual void TestRenameLimit() { ObjectId aId = Blob("foo\nbar\nbaz\nblarg\n"); ObjectId bId = Blob("foo\nbar\nbaz\nblah\n"); DiffEntry a = DiffEntry.Add(PATH_A, aId); DiffEntry b = DiffEntry.Delete(PATH_B, bId); ObjectId cId = Blob("a\nb\nc\nd\n"); ObjectId dId = Blob("a\nb\nc\n"); DiffEntry c = DiffEntry.Add(PATH_H, cId); DiffEntry d = DiffEntry.Delete(PATH_Q, dId); rd.Add(a); rd.Add(b); rd.Add(c); rd.Add(d); rd.SetRenameLimit(1); NUnit.Framework.Assert.IsTrue(rd.IsOverRenameLimit()); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(4, entries.Count); NUnit.Framework.Assert.AreSame(a, entries[0]); NUnit.Framework.Assert.AreSame(b, entries[1]); NUnit.Framework.Assert.AreSame(c, entries[2]); NUnit.Framework.Assert.AreSame(d, entries[3]); }
public virtual void TestCreateFileHeader_Modify() { ObjectId adId = Blob("a\nd\n"); ObjectId abcdId = Blob("a\nb\nc\nd\n"); string diffHeader = MakeDiffHeader(PATH_A, PATH_A, adId, abcdId); DiffEntry ad = DiffEntry.Delete(PATH_A, adId); DiffEntry abcd = DiffEntry.Add(PATH_A, abcdId); DiffEntry mod = DiffEntry.Pair(DiffEntry.ChangeType.MODIFY, ad, abcd, 0); FileHeader fh = df.ToFileHeader(mod); NUnit.Framework.Assert.AreEqual(diffHeader, RawParseUtils.Decode(fh.GetBuffer())); NUnit.Framework.Assert.AreEqual(0, fh.GetStartOffset()); NUnit.Framework.Assert.AreEqual(fh.GetBuffer().Length, fh.GetEndOffset()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, fh.GetPatchType()); NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count); HunkHeader hh = fh.GetHunks()[0]; NUnit.Framework.Assert.AreEqual(1, hh.ToEditList().Count); EditList el = hh.ToEditList(); NUnit.Framework.Assert.AreEqual(1, el.Count); Edit e = el[0]; NUnit.Framework.Assert.AreEqual(1, e.GetBeginA()); NUnit.Framework.Assert.AreEqual(1, e.GetEndA()); NUnit.Framework.Assert.AreEqual(1, e.GetBeginB()); NUnit.Framework.Assert.AreEqual(3, e.GetEndB()); NUnit.Framework.Assert.AreEqual(Edit.Type.INSERT, e.GetType()); }
public virtual void TestCreateFileHeader_Add() { ObjectId adId = Blob("a\nd\n"); DiffEntry ent = DiffEntry.Add("FOO", adId); FileHeader fh = df.ToFileHeader(ent); string diffHeader = "diff --git a/FOO b/FOO\n" + "new file mode " + REGULAR_FILE + "\n" + "index " + ObjectId.ZeroId.Abbreviate(8).Name + ".." + adId.Abbreviate( 8).Name + "\n" + "--- /dev/null\n" + "+++ b/FOO\n"; // // // NUnit.Framework.Assert.AreEqual(diffHeader, RawParseUtils.Decode(fh.GetBuffer())); NUnit.Framework.Assert.AreEqual(0, fh.GetStartOffset()); NUnit.Framework.Assert.AreEqual(fh.GetBuffer().Length, fh.GetEndOffset()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, fh.GetPatchType()); NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count); HunkHeader hh = fh.GetHunks()[0]; NUnit.Framework.Assert.AreEqual(1, hh.ToEditList().Count); EditList el = hh.ToEditList(); NUnit.Framework.Assert.AreEqual(1, el.Count); Edit e = el[0]; NUnit.Framework.Assert.AreEqual(0, e.GetBeginA()); NUnit.Framework.Assert.AreEqual(0, e.GetEndA()); NUnit.Framework.Assert.AreEqual(0, e.GetBeginB()); NUnit.Framework.Assert.AreEqual(2, e.GetEndB()); NUnit.Framework.Assert.AreEqual(Edit.Type.INSERT, e.GetType()); }
public virtual void TestNoRenames_EmptyFile1() { ObjectId aId = Blob(string.Empty); DiffEntry a = DiffEntry.Add(PATH_A, aId); rd.Add(a); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(1, entries.Count); NUnit.Framework.Assert.AreSame(a, entries[0]); }
public virtual void TestExactRename_OneRename() { ObjectId foo = Blob("foo"); DiffEntry a = DiffEntry.Add(PATH_A, foo); DiffEntry b = DiffEntry.Delete(PATH_Q, foo); rd.Add(a); rd.Add(b); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(1, entries.Count); AssertRename(b, a, 100, entries[0]); }
public virtual void TestInexactRename_SameContentMultipleTimes() { ObjectId aId = Blob("a\na\na\na\n"); ObjectId bId = Blob("a\na\na\n"); DiffEntry a = DiffEntry.Add(PATH_A, aId); DiffEntry b = DiffEntry.Delete(PATH_Q, bId); rd.Add(a); rd.Add(b); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(1, entries.Count); AssertRename(b, a, 74, entries[0]); }
public virtual void TestInexactRename_LastByteDifferent() { ObjectId aId = Blob("foo\nbar\na"); ObjectId bId = Blob("foo\nbar\nb"); DiffEntry a = DiffEntry.Add(PATH_A, aId); DiffEntry b = DiffEntry.Delete(PATH_Q, bId); rd.Add(a); rd.Add(b); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(1, entries.Count); AssertRename(b, a, 88, entries[0]); }
public virtual void TestInexactRename_OnePair() { ObjectId aId = Blob("foo\nbar\nbaz\nblarg\n"); ObjectId bId = Blob("foo\nbar\nbaz\nblah\n"); DiffEntry a = DiffEntry.Add(PATH_A, aId); DiffEntry b = DiffEntry.Delete(PATH_Q, bId); rd.Add(a); rd.Add(b); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(1, entries.Count); AssertRename(b, a, 66, entries[0]); }
public virtual void TestInexactRenames_OnePair2() { ObjectId aId = Blob("ab\nab\nab\nac\nad\nae\n"); ObjectId bId = Blob("ac\nab\nab\nab\naa\na0\na1\n"); DiffEntry a = DiffEntry.Add(PATH_A, aId); DiffEntry b = DiffEntry.Delete(PATH_Q, bId); rd.Add(a); rd.Add(b); rd.SetRenameScore(50); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(1, entries.Count); AssertRename(b, a, 57, entries[0]); }
public virtual void TestNoRenames_GitlinkAndFile() { ObjectId aId = Blob("src/dest"); DiffEntry a = DiffEntry.Add(PATH_A, aId); DiffEntry b = DiffEntry.Delete(PATH_Q, aId); b.oldMode = FileMode.GITLINK; rd.Add(a); rd.Add(b); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(2, entries.Count); NUnit.Framework.Assert.AreSame(a, entries[0]); NUnit.Framework.Assert.AreSame(b, entries[1]); }
public virtual void TestNoRenames_EmptyFile2() { ObjectId aId = Blob(string.Empty); ObjectId bId = Blob("blah"); DiffEntry a = DiffEntry.Add(PATH_A, aId); DiffEntry b = DiffEntry.Delete(PATH_Q, bId); rd.Add(a); rd.Add(b); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(2, entries.Count); NUnit.Framework.Assert.AreSame(a, entries[0]); NUnit.Framework.Assert.AreSame(b, entries[1]); }
public virtual void TestNoRenames_SymlinkAndFileSamePath() { ObjectId aId = Blob("src/dest"); DiffEntry a = DiffEntry.Delete(PATH_A, aId); DiffEntry b = DiffEntry.Add(PATH_A, aId); a.oldMode = FileMode.SYMLINK; rd.Add(a); rd.Add(b); // Deletes should be first IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(2, entries.Count); NUnit.Framework.Assert.AreSame(a, entries[0]); NUnit.Framework.Assert.AreSame(b, entries[1]); }
public virtual void TestCreateFileHeader_Binary() { ObjectId adId = Blob("a\nd\n"); ObjectId binId = Blob("a\nb\nc\n\x0\x0\x0\x0d\n"); string diffHeader = MakeDiffHeader(PATH_A, PATH_B, adId, binId) + "Binary files differ\n"; DiffEntry ad = DiffEntry.Delete(PATH_A, adId); DiffEntry abcd = DiffEntry.Add(PATH_B, binId); DiffEntry mod = DiffEntry.Pair(DiffEntry.ChangeType.MODIFY, ad, abcd, 0); FileHeader fh = df.ToFileHeader(mod); NUnit.Framework.Assert.AreEqual(diffHeader, RawParseUtils.Decode(fh.GetBuffer())); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.BINARY, fh.GetPatchType()); NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count); HunkHeader hh = fh.GetHunks()[0]; NUnit.Framework.Assert.AreEqual(0, hh.ToEditList().Count); }
public virtual void TestExactRename_OneRenameOneModify() { ObjectId foo = Blob("foo"); ObjectId bar = Blob("bar"); DiffEntry a = DiffEntry.Add(PATH_A, foo); DiffEntry b = DiffEntry.Delete(PATH_Q, foo); DiffEntry c = DiffEntry.Modify(PATH_H); c.newId = c.oldId = AbbreviatedObjectId.FromObjectId(bar); rd.Add(a); rd.Add(b); rd.Add(c); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(2, entries.Count); AssertRename(b, a, 100, entries[0]); NUnit.Framework.Assert.AreSame(c, entries[1]); }
public virtual void TestExactRename_DifferentObjects() { ObjectId foo = Blob("foo"); ObjectId bar = Blob("bar"); DiffEntry a = DiffEntry.Add(PATH_A, foo); DiffEntry h = DiffEntry.Add(PATH_H, foo); DiffEntry q = DiffEntry.Delete(PATH_Q, bar); rd.Add(a); rd.Add(h); rd.Add(q); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(3, entries.Count); NUnit.Framework.Assert.AreSame(a, entries[0]); NUnit.Framework.Assert.AreSame(h, entries[1]); NUnit.Framework.Assert.AreSame(q, entries[2]); }
public virtual void TestCreateFileHeader_GitLink() { ObjectId aId = Blob("a\n"); ObjectId bId = Blob("b\n"); string diffHeader = MakeDiffHeaderModeChange(PATH_A, PATH_A, aId, bId, GITLINK, REGULAR_FILE ) + "-Subproject commit " + aId.Name + "\n"; DiffEntry ad = DiffEntry.Delete(PATH_A, aId); ad.oldMode = FileMode.GITLINK; DiffEntry abcd = DiffEntry.Add(PATH_A, bId); DiffEntry mod = DiffEntry.Pair(DiffEntry.ChangeType.MODIFY, ad, abcd, 0); FileHeader fh = df.ToFileHeader(mod); NUnit.Framework.Assert.AreEqual(diffHeader, RawParseUtils.Decode(fh.GetBuffer())); NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count); HunkHeader hh = fh.GetHunks()[0]; NUnit.Framework.Assert.AreEqual(0, hh.ToEditList().Count); }
public virtual void TestExactRename_OneDeleteManyAdds() { ObjectId foo = Blob("foo"); DiffEntry a = DiffEntry.Add("src/com/foo/a.java", foo); DiffEntry b = DiffEntry.Add("src/com/foo/b.java", foo); DiffEntry c = DiffEntry.Add("c.txt", foo); DiffEntry d = DiffEntry.Delete("d.txt", foo); rd.Add(a); rd.Add(b); rd.Add(c); rd.Add(d); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(3, entries.Count); AssertRename(d, c, 100, entries[0]); AssertCopy(d, a, 100, entries[1]); AssertCopy(d, b, 100, entries[2]); }
public virtual void TestBreakModify_BreakNone() { ObjectId aId = Blob("foo"); ObjectId bId = Blob("bar"); DiffEntry m = DiffEntry.Modify(PATH_A); m.oldId = AbbreviatedObjectId.FromObjectId(aId); m.newId = AbbreviatedObjectId.FromObjectId(bId); DiffEntry a = DiffEntry.Add(PATH_B, aId); rd.Add(a); rd.Add(m); rd.SetBreakScore(-1); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(2, entries.Count); NUnit.Framework.Assert.AreSame(m, entries[0]); NUnit.Framework.Assert.AreSame(a, entries[1]); }
public virtual void TestBreakModify_BreakAll() { ObjectId aId = Blob("foo"); ObjectId bId = Blob("bar"); DiffEntry m = DiffEntry.Modify(PATH_A); m.oldId = AbbreviatedObjectId.FromObjectId(aId); m.newId = AbbreviatedObjectId.FromObjectId(bId); DiffEntry a = DiffEntry.Add(PATH_B, aId); rd.Add(a); rd.Add(m); rd.SetBreakScore(101); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(2, entries.Count); AssertAdd(PATH_A, bId, FileMode.REGULAR_FILE, entries[0]); AssertRename(DiffEntry.BreakModify(m)[0], a, 100, entries[1]); }
public virtual void TestExactRename_ManyRenames() { ObjectId foo = Blob("foo"); ObjectId bar = Blob("bar"); DiffEntry a = DiffEntry.Add(PATH_A, foo); DiffEntry b = DiffEntry.Delete(PATH_Q, foo); DiffEntry c = DiffEntry.Add(PATH_H, bar); DiffEntry d = DiffEntry.Delete(PATH_B, bar); rd.Add(a); rd.Add(b); rd.Add(c); rd.Add(d); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(2, entries.Count); AssertRename(b, a, 100, entries[0]); AssertRename(d, c, 100, entries[1]); }
public virtual void TestExactRename_MultipleIdenticalDeletes() { ObjectId foo = Blob("foo"); DiffEntry a = DiffEntry.Delete(PATH_A, foo); DiffEntry b = DiffEntry.Delete(PATH_B, foo); DiffEntry c = DiffEntry.Delete(PATH_H, foo); DiffEntry d = DiffEntry.Add(PATH_Q, foo); rd.Add(a); rd.Add(b); rd.Add(c); rd.Add(d); // Pairs the add with the first delete added IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(3, entries.Count); NUnit.Framework.Assert.AreEqual(b, entries[0]); NUnit.Framework.Assert.AreEqual(c, entries[1]); AssertRename(a, d, 100, entries[2]); }
public virtual void TestBreakModify_DontBreakAboveScore() { ObjectId aId = Blob("blah\nblah\nfoo"); ObjectId bId = Blob("blah\nblah\nbar"); DiffEntry m = DiffEntry.Modify(PATH_A); m.oldId = AbbreviatedObjectId.FromObjectId(aId); m.newId = AbbreviatedObjectId.FromObjectId(bId); DiffEntry a = DiffEntry.Add(PATH_B, aId); rd.Add(a); rd.Add(m); rd.SetBreakScore(20); // Should not break the modify IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(2, entries.Count); NUnit.Framework.Assert.AreSame(m, entries[0]); NUnit.Framework.Assert.AreSame(a, entries[1]); }
public virtual void TestExactRename_PathBreaksTie() { ObjectId foo = Blob("foo"); DiffEntry a = DiffEntry.Add("src/com/foo/a.java", foo); DiffEntry b = DiffEntry.Delete("src/com/foo/b.java", foo); DiffEntry c = DiffEntry.Add("c.txt", foo); DiffEntry d = DiffEntry.Delete("d.txt", foo); DiffEntry e = DiffEntry.Add("the_e_file.txt", foo); // Add out of order to avoid first-match succeeding rd.Add(a); rd.Add(d); rd.Add(e); rd.Add(b); rd.Add(c); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(3, entries.Count); AssertRename(d, c, 100, entries[0]); AssertRename(b, a, 100, entries[1]); AssertCopy(d, e, 100, entries[2]); }
public virtual void TestInexactRename_OneRenameTwoUnrelatedFiles() { ObjectId aId = Blob("foo\nbar\nbaz\nblarg\n"); ObjectId bId = Blob("foo\nbar\nbaz\nblah\n"); DiffEntry a = DiffEntry.Add(PATH_A, aId); DiffEntry b = DiffEntry.Delete(PATH_Q, bId); ObjectId cId = Blob("some\nsort\nof\ntext\n"); ObjectId dId = Blob("completely\nunrelated\ntext\n"); DiffEntry c = DiffEntry.Add(PATH_B, cId); DiffEntry d = DiffEntry.Delete(PATH_H, dId); rd.Add(a); rd.Add(b); rd.Add(c); rd.Add(d); IList <DiffEntry> entries = rd.Compute(); NUnit.Framework.Assert.AreEqual(3, entries.Count); AssertRename(b, a, 66, entries[0]); NUnit.Framework.Assert.AreSame(c, entries[1]); NUnit.Framework.Assert.AreSame(d, entries[2]); }