예제 #1
0
        public void testAddTwo()
        {
            Edit     e1 = new Edit(1, 2, 1, 1);
            Edit     e2 = new Edit(8, 8, 8, 12);
            EditList l  = new EditList();

            l.Add(e1);
            l.Add(e2);
            Assert.AreEqual(2, l.size());
            Assert.AreSame(e1, l.get(0));
            Assert.AreSame(e2, l.get(1));

            IEnumerator i = l.GetEnumerator();

            i.Reset();
            i.MoveNext();
            Assert.AreSame(e1, i.Current);
            i.MoveNext();
            Assert.AreSame(e2, i.Current);

            Assert.IsTrue(l.Equals(l));
            Assert.IsFalse(l.Equals(new EditList()));

            EditList l2 = new EditList();

            l2.Add(e1);
            l2.Add(e2);
            Assert.IsTrue(l.Equals(l2));
            Assert.IsTrue(l2.Equals(l));
            Assert.AreEqual(l.GetHashCode(), l2.GetHashCode());
        }
예제 #2
0
        public void testFileHeader()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testGetText_BothISO88591.patch");
            FileHeader fh = p.getFiles()[0];
            EditList   e  = fh.ToEditList();

            Assert.AreEqual(2, e.size());
            Assert.AreEqual(new Edit(4 - 1, 5 - 1, 4 - 1, 5 - 1), e.get(0));
            Assert.AreEqual(new Edit(16 - 1, 17 - 1, 16 - 1, 17 - 1), e.get(1));
        }
예제 #3
0
        public void testSet()
        {
            Edit     e1 = new Edit(1, 2, 1, 1);
            Edit     e2 = new Edit(3, 4, 3, 3);
            EditList l  = new EditList();

            l.Add(e1);
            Assert.AreSame(e1, l.get(0));
            Assert.AreSame(e1, l.set(0, e2));
            Assert.AreSame(e2, l.get(0));
        }
예제 #4
0
        public void testTypes()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testEditList_Types.patch");
            FileHeader fh = p.getFiles()[0];
            EditList   e  = fh.ToEditList();

            Assert.AreEqual(3, e.size());
            Assert.AreEqual(new Edit(3 - 1, 3 - 1, 3 - 1, 4 - 1), e.get(0));
            Assert.AreEqual(new Edit(17 - 1, 19 - 1, 18 - 1, 18 - 1), e.get(1));
            Assert.AreEqual(new Edit(23 - 1, 25 - 1, 22 - 1, 28 - 1), e.get(2));
        }
예제 #5
0
        public void testAddOne()
        {
            Edit     e = new Edit(1, 2, 1, 1);
            EditList l = new EditList();

            l.Add(e);
            Assert.AreEqual(1, l.size());
            Assert.IsFalse(l.isEmpty());
            Assert.AreSame(e, l.get(0));
            IEnumerator i = l.GetEnumerator();

            i.Reset();
            i.MoveNext();
            Assert.AreSame(e, i.Current);

            Assert.IsTrue(l.Equals(l));
            Assert.IsFalse(l.Equals(new EditList()));

            EditList l2 = new EditList();

            l2.Add(e);
            Assert.IsTrue(l.Equals(l2));
            Assert.IsTrue(l2.Equals(l));
            Assert.AreEqual(l.GetHashCode(), l2.GetHashCode());
        }
예제 #6
0
        public void testRemove()
        {
            Edit     e1 = new Edit(1, 2, 1, 1);
            Edit     e2 = new Edit(8, 8, 8, 12);
            EditList l  = new EditList();

            l.Add(e1);
            l.Add(e2);
            l.Remove(e1);
            Assert.AreEqual(1, l.size());
            Assert.AreSame(e2, l.get(0));
        }
예제 #7
0
        public void testHunkHeader()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testGetText_BothISO88591.patch");
            FileHeader fh = p.getFiles()[0];

            EditList list0 = fh.Hunks[0].ToEditList();

            Assert.AreEqual(1, list0.size());
            Assert.AreEqual(new Edit(4 - 1, 5 - 1, 4 - 1, 5 - 1), list0.get(0));

            EditList list1 = fh.Hunks[1].ToEditList();

            Assert.AreEqual(1, list1.size());
            Assert.AreEqual(new Edit(16 - 1, 17 - 1, 16 - 1, 17 - 1), list1.get(0));
        }
예제 #8
0
        public void testAddOne()
        {
            Edit e = new Edit(1, 2, 1, 1);
            EditList l = new EditList();
            l.Add(e);
            Assert.AreEqual(1, l.size());
            Assert.IsFalse(l.isEmpty());
            Assert.AreSame(e, l.get(0));
            IEnumerator i = l.GetEnumerator();
            i.Reset();
            i.MoveNext();
            Assert.AreSame(e, i.Current);

            Assert.IsTrue(l.Equals(l));
            Assert.IsFalse(l.Equals(new EditList()));

            EditList l2 = new EditList();
            l2.Add(e);
            Assert.IsTrue(l.Equals(l2));
            Assert.IsTrue(l2.Equals(l));
            Assert.AreEqual(l.GetHashCode(), l2.GetHashCode());
        }
예제 #9
0
        private void FormatEdits(Stream @out, RawText a, RawText b, EditList edits)
        {
            for (int curIdx = 0; curIdx < edits.Count; /* */)
            {
                Edit curEdit = edits.get(curIdx);
                int endIdx = FindCombinedEnd(edits, curIdx);
                Edit endEdit = edits.get(endIdx);

                int aCur = Math.Max(0, curEdit.BeginA - _context);
                int bCur = Math.Max(0, curEdit.BeginB - _context);
                int aEnd = Math.Min(a.size(), endEdit.EndA + _context);
                int bEnd = Math.Min(b.size(), endEdit.EndB + _context);

                WriteHunkHeader(@out, aCur, aEnd, bCur, bEnd);

                while (aCur < aEnd || bCur < bEnd)
                {
                    if (aCur < curEdit.BeginA || endIdx + 1 < curIdx)
                    {
                        WriteLine(@out, ' ', a, aCur);
                        aCur++;
                        bCur++;
                    }
                    else if (aCur < curEdit.EndA)
                    {
                        WriteLine(@out, '-', a, aCur++);

                    }
                    else if (bCur < curEdit.EndB)
                    {
                        WriteLine(@out, '+', b, bCur++);
                    }

                    if (End(curEdit, aCur, bCur) && ++curIdx < edits.Count)
                    {
                        curEdit = edits.get(curIdx);
                    }
                }
            }
        }
예제 #10
0
        public void testAddTwo()
        {
            Edit e1 = new Edit(1, 2, 1, 1);
            Edit e2 = new Edit(8, 8, 8, 12);
            EditList l = new EditList();
            l.Add(e1);
            l.Add(e2);
            Assert.AreEqual(2, l.size());
            Assert.AreSame(e1, l.get(0));
            Assert.AreSame(e2, l.get(1));

            IEnumerator i = l.GetEnumerator();
            i.Reset();
            i.MoveNext();
            Assert.AreSame(e1, i.Current);
            i.MoveNext();
            Assert.AreSame(e2, i.Current);

            Assert.IsTrue(l.Equals(l));
            Assert.IsFalse(l.Equals(new EditList()));

            EditList l2 = new EditList();
            l2.Add(e1);
            l2.Add(e2);
            Assert.IsTrue(l.Equals(l2));
            Assert.IsTrue(l2.Equals(l));
            Assert.AreEqual(l.GetHashCode(), l2.GetHashCode());
        }
예제 #11
0
 public void testRemove()
 {
     Edit e1 = new Edit(1, 2, 1, 1);
     Edit e2 = new Edit(8, 8, 8, 12);
     EditList l = new EditList();
     l.Add(e1);
     l.Add(e2);
     l.Remove(e1);
     Assert.AreEqual(1, l.size());
     Assert.AreSame(e2, l.get(0));
 }
예제 #12
0
 public void testSet()
 {
     Edit e1 = new Edit(1, 2, 1, 1);
     Edit e2 = new Edit(3, 4, 3, 3);
     EditList l = new EditList();
     l.Add(e1);
     Assert.AreSame(e1, l.get(0));
     Assert.AreSame(e1, l.set(0, e2));
     Assert.AreSame(e2, l.get(0));
 }