public virtual void TestParseGitFileName_Foo() { string name = "foo"; FileHeader fh = Header(name); NUnit.Framework.Assert.AreEqual(GitLine(name).Length, fh.ParseGitFileName(0, fh.buf .Length)); NUnit.Framework.Assert.AreEqual(name, fh.GetOldPath()); NUnit.Framework.Assert.AreSame(fh.GetOldPath(), fh.GetNewPath()); NUnit.Framework.Assert.IsFalse(fh.HasMetaDataChanges()); }
public virtual void TestParseGitFileName_SrcFooCNonStandardPrefix() { string name = "src/foo/bar/argh/code.c"; string header = "project-v-1.0/" + name + " mydev/" + name + "\n"; FileHeader fh = Data(header + "-"); NUnit.Framework.Assert.AreEqual(header.Length, fh.ParseGitFileName(0, fh.buf.Length )); NUnit.Framework.Assert.AreEqual(name, fh.GetOldPath()); NUnit.Framework.Assert.AreSame(fh.GetOldPath(), fh.GetNewPath()); NUnit.Framework.Assert.IsFalse(fh.HasMetaDataChanges()); }
public virtual void TestParseGitFileName_DqFooSpLfNulBar() { string name = "foo \n\x0bar"; string dqName = "foo \\n\\0bar"; FileHeader fh = DqHeader(dqName); NUnit.Framework.Assert.AreEqual(DqGitLine(dqName).Length, fh.ParseGitFileName(0, fh.buf.Length)); NUnit.Framework.Assert.AreEqual(name, fh.GetOldPath()); NUnit.Framework.Assert.AreSame(fh.GetOldPath(), fh.GetNewPath()); NUnit.Framework.Assert.IsFalse(fh.HasMetaDataChanges()); }
public virtual void TestParseAbbrIndexLine_NoMode() { int a = 7; string oid = "78981922613b2afb6025042ff6bd878ac1994e85"; string nid = "61780798228d17af2d34fce4cfbdf35556832472"; FileHeader fh = Data("diff --git a/a b/a\n" + "index " + Sharpen.Runtime.Substring (oid, 0, a - 1) + ".." + Sharpen.Runtime.Substring(nid, 0, a - 1) + "\n" + "--- a/a\n" + "+++ b/a\n"); AssertParse(fh); NUnit.Framework.Assert.AreEqual("a", fh.GetOldPath()); NUnit.Framework.Assert.AreEqual("a", fh.GetNewPath()); NUnit.Framework.Assert.IsNull(fh.GetOldMode()); NUnit.Framework.Assert.IsNull(fh.GetNewMode()); NUnit.Framework.Assert.IsFalse(fh.HasMetaDataChanges()); NUnit.Framework.Assert.IsNotNull(fh.GetOldId()); NUnit.Framework.Assert.IsNotNull(fh.GetNewId()); NUnit.Framework.Assert.IsFalse(fh.GetOldId().IsComplete); NUnit.Framework.Assert.IsFalse(fh.GetNewId().IsComplete); NUnit.Framework.Assert.AreEqual(Sharpen.Runtime.Substring(oid, 0, a - 1), fh.GetOldId ().Name); NUnit.Framework.Assert.AreEqual(Sharpen.Runtime.Substring(nid, 0, a - 1), fh.GetNewId ().Name); NUnit.Framework.Assert.IsTrue(ObjectId.FromString(oid).StartsWith(fh.GetOldId())); NUnit.Framework.Assert.IsTrue(ObjectId.FromString(nid).StartsWith(fh.GetNewId())); }
public virtual void TestParseGitFileName_FailFooBar() { FileHeader fh = Data("a/foo b/bar\n-"); NUnit.Framework.Assert.IsTrue(fh.ParseGitFileName(0, fh.buf.Length) > 0); NUnit.Framework.Assert.IsNull(fh.GetOldPath()); NUnit.Framework.Assert.IsNull(fh.GetNewPath()); NUnit.Framework.Assert.IsFalse(fh.HasMetaDataChanges()); }
public virtual void TestParseUnicodeName_NewFile() { FileHeader fh = Data("diff --git \"a/\\303\\205ngstr\\303\\266m\" \"b/\\303\\205ngstr\\303\\266m\"\n" + "new file mode 100644\n" + "index 0000000..7898192\n" + "--- /dev/null\n" + "+++ \"b/\\303\\205ngstr\\303\\266m\"\n" + "@@ -0,0 +1 @@\n" + "+a\n"); AssertParse(fh); NUnit.Framework.Assert.AreEqual("/dev/null", fh.GetOldPath()); NUnit.Framework.Assert.AreSame(DiffEntry.DEV_NULL, fh.GetOldPath()); NUnit.Framework.Assert.AreEqual("\u00c5ngstr\u00f6m", fh.GetNewPath()); NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.ADD, fh.GetChangeType()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, fh.GetPatchType()); NUnit.Framework.Assert.IsTrue(fh.HasMetaDataChanges()); NUnit.Framework.Assert.AreSame(FileMode.MISSING, fh.GetOldMode()); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, fh.GetNewMode()); NUnit.Framework.Assert.AreEqual("0000000", fh.GetOldId().Name); NUnit.Framework.Assert.AreEqual("7898192", fh.GetNewId().Name); NUnit.Framework.Assert.AreEqual(0, fh.GetScore()); }
public virtual void TestParseCopy100() { FileHeader fh = Data("diff --git a/a b/ c/\\303\\205ngstr\\303\\266m\n" + "similarity index 100%\n" + "copy from a\n" + "copy to \" c/\\303\\205ngstr\\303\\266m\"\n"); int ptr = fh.ParseGitFileName(0, fh.buf.Length); NUnit.Framework.Assert.IsTrue(ptr > 0); NUnit.Framework.Assert.IsNull(fh.GetOldPath()); // can't parse names on a copy NUnit.Framework.Assert.IsNull(fh.GetNewPath()); ptr = fh.ParseGitHeaders(ptr, fh.buf.Length); NUnit.Framework.Assert.IsTrue(ptr > 0); NUnit.Framework.Assert.AreEqual("a", fh.GetOldPath()); NUnit.Framework.Assert.AreEqual(" c/\u00c5ngstr\u00f6m", fh.GetNewPath()); NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.COPY, fh.GetChangeType()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, fh.GetPatchType()); NUnit.Framework.Assert.IsTrue(fh.HasMetaDataChanges()); NUnit.Framework.Assert.IsNull(fh.GetOldId()); NUnit.Framework.Assert.IsNull(fh.GetNewId()); NUnit.Framework.Assert.IsNull(fh.GetOldMode()); NUnit.Framework.Assert.IsNull(fh.GetNewMode()); NUnit.Framework.Assert.AreEqual(100, fh.GetScore()); }
public virtual void TestParseModeChange() { FileHeader fh = Data("diff --git a/a b b/a b\n" + "old mode 100644\n" + "new mode 100755\n" ); AssertParse(fh); NUnit.Framework.Assert.AreEqual("a b", fh.GetOldPath()); NUnit.Framework.Assert.AreEqual("a b", fh.GetNewPath()); NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, fh.GetChangeType()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, fh.GetPatchType()); NUnit.Framework.Assert.IsTrue(fh.HasMetaDataChanges()); NUnit.Framework.Assert.IsNull(fh.GetOldId()); NUnit.Framework.Assert.IsNull(fh.GetNewId()); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, fh.GetOldMode()); NUnit.Framework.Assert.AreSame(FileMode.EXECUTABLE_FILE, fh.GetNewMode()); NUnit.Framework.Assert.AreEqual(0, fh.GetScore()); }
public virtual void TestParseFullIndexLine_WithMode() { string oid = "78981922613b2afb6025042ff6bd878ac1994e85"; string nid = "61780798228d17af2d34fce4cfbdf35556832472"; FileHeader fh = Data("diff --git a/a b/a\n" + "index " + oid + ".." + nid + " 100644\n" + "--- a/a\n" + "+++ b/a\n"); AssertParse(fh); NUnit.Framework.Assert.AreEqual("a", fh.GetOldPath()); NUnit.Framework.Assert.AreEqual("a", fh.GetNewPath()); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, fh.GetOldMode()); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, fh.GetNewMode()); NUnit.Framework.Assert.IsFalse(fh.HasMetaDataChanges()); NUnit.Framework.Assert.IsNotNull(fh.GetOldId()); NUnit.Framework.Assert.IsNotNull(fh.GetNewId()); NUnit.Framework.Assert.IsTrue(fh.GetOldId().IsComplete); NUnit.Framework.Assert.IsTrue(fh.GetNewId().IsComplete); NUnit.Framework.Assert.AreEqual(ObjectId.FromString(oid), fh.GetOldId().ToObjectId ()); NUnit.Framework.Assert.AreEqual(ObjectId.FromString(nid), fh.GetNewId().ToObjectId ()); }