Esempio n. 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());
        }
Esempio n. 2
0
 public void testCreateEmpty()
 {
     Edit e = new Edit(1, 3);
     Assert.AreEqual(1, e.BeginA);
     Assert.AreEqual(1, e.EndA);
     Assert.AreEqual(3, e.BeginB);
     Assert.AreEqual(3, e.EndB);
 }
Esempio n. 3
0
 public void testCreate()
 {
     Edit e = new Edit(1, 2, 3, 4);
     Assert.AreEqual(1, e.BeginA);
     Assert.AreEqual(2, e.EndA);
     Assert.AreEqual(3, e.BeginB);
     Assert.AreEqual(4, e.EndB);
 }
Esempio n. 4
0
	    public void testCreate()
        {
		    Edit e = new Edit(1, 2, 3, 4);
		    Assert.AreEqual(1, e.getBeginA());
		    Assert.AreEqual(2, e.getEndA());
		    Assert.AreEqual(3, e.getBeginB());
		    Assert.AreEqual(4, e.getEndB());
	    }
Esempio n. 5
0
	    public void testCreateEmpty()
        {
		    Edit e = new Edit(1, 3);
		    Assert.AreEqual(1, e.getBeginA());
		    Assert.AreEqual(1, e.getEndA());
		    Assert.AreEqual(3, e.getBeginB());
		    Assert.AreEqual(3, e.getEndB());
	    }
Esempio n. 6
0
        public void testEquals1()
        {
            Edit e1 = new Edit(1, 2, 3, 4);
            Edit e2 = new Edit(1, 2, 3, 4);

            Assert.IsTrue(e1.Equals(e1));
            Assert.IsTrue(e1.Equals(e2));
            Assert.IsTrue(e2.Equals(e1));
            Assert.AreEqual(e1.GetHashCode(), e2.GetHashCode());
            Assert.IsFalse(e1.Equals(""));
        }
Esempio n. 7
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());
	    }
Esempio n. 8
0
 public void testType_Replace()
 {
     Edit e = new Edit(1, 2, 1, 4);
     Assert.AreEqual(Edit.Type.REPLACE, e.EditType);
 }
Esempio n. 9
0
 public void testType_Insert()
 {
     Edit e = new Edit(1, 1, 1, 2);
     Assert.AreEqual(Edit.Type.INSERT, e.EditType);
 }
Esempio n. 10
0
 public void testType_Delete()
 {
     Edit e = new Edit(1, 2, 1, 1);
     Assert.AreEqual(Edit.Type.DELETE, e.EditType);
 }
Esempio n. 11
0
	    public Edit set(int index, Edit element)
        {
            Edit retval = (Edit)this[index];
            this[index] = element;
            return retval;
	    }
Esempio n. 12
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));
	    }
Esempio n. 13
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));
	    }
Esempio n. 14
0
        /// <summary>
        /// Returns a list describing the content edits performed within the hunk.
        /// </summary>
        /// <returns></returns>
        public EditList ToEditList()
        {
            var r = new EditList();
            byte[] buf = _file.Buffer;
            int c = RawParseUtils.nextLF(buf, _startOffset);
            int oLine = _oldImage.StartLine;
            int nLine = NewStartLine;
            Edit inEdit = null;

            for (; c < EndOffset; c = RawParseUtils.nextLF(buf, c))
            {
                bool breakScan;

                switch (buf[c])
                {
                    case (byte)' ':
                    case (byte)'\n':
                        inEdit = null;
                        oLine++;
                        nLine++;
                        continue;

                    case (byte)'-':
                        if (inEdit == null)
                        {
                            inEdit = new Edit(oLine - 1, nLine - 1);
                            r.Add(inEdit);
                        }
                        oLine++;
                        inEdit.ExtendA();
                        continue;

                    case (byte)'+':
                        if (inEdit == null)
                        {
                            inEdit = new Edit(oLine - 1, nLine - 1);
                            r.Add(inEdit);
                        }
                        nLine++;
                        inEdit.ExtendB();
                        continue;

                    case (byte)'\\': // Matches "\ No newline at end of file"
                        continue;

                    default:
                        breakScan = true;
                        break;
                }

                if (breakScan)
                {
                    break;
                }
            }

            return r;
        }
Esempio n. 15
0
	    /** @return a list describing the content edits performed within the hunk. */
	    public EditList toEditList()
        {
		    EditList r = new EditList();
		    byte[] buf = file.buf;
		    int c = RawParseUtils.nextLF(buf, startOffset);
		    int oLine = old.startLine;
		    int nLine = newStartLine;
		    Edit inEdit = null;

            bool break_scan = false;
		    for (; c < endOffset; c = RawParseUtils.nextLF(buf, c)) {
			    switch (buf[c]) {
			    case (byte)' ':
			    case (byte)'\n':
				    inEdit = null;
				    oLine++;
				    nLine++;
				    continue;

			    case (byte)'-':
				    if (inEdit == null) {
					    inEdit = new Edit(oLine - 1, nLine - 1);
					    r.Add(inEdit);
				    }
				    oLine++;
				    inEdit.extendA();
				    continue;

			    case (byte)'+':
				    if (inEdit == null) {
					    inEdit = new Edit(oLine - 1, nLine - 1);
					    r.Add(inEdit);
				    }
				    nLine++;
				    inEdit.extendB();
				    continue;

			    case (byte)'\\': // Matches "\ No newline at end of file"
				    continue;

			    default:
				    break_scan = true;
                    break;
			    }
                if (break_scan)
                    break;
		    }
		    return r;
	    }
Esempio n. 16
0
 private static bool End(Edit edit, int a, int b)
 {
     return edit.EndA <= a && edit.EndB <= b;
 }
Esempio n. 17
0
        public void testExtendB()
        {
            Edit e = new Edit(1, 2, 1, 1);

            e.ExtendB();
            Assert.AreEqual(new Edit(1, 2, 1, 2), e);

            e.ExtendB();
            Assert.AreEqual(new Edit(1, 2, 1, 3), e);
        }
Esempio n. 18
0
 public void testToString()
 {
     Edit e = new Edit(1, 2, 1, 4);
     Assert.AreEqual("REPLACE(1-2,1-4)", e.ToString());
 }
Esempio n. 19
0
	    public void Add(int index, Edit element)
        {
		    this.Insert(index, element);
	    }
Esempio n. 20
0
	    public void testExtendA()
        {
		    Edit e = new Edit(1, 2, 1, 1);

		    e.extendA();
		    Assert.AreEqual(new Edit(1, 3, 1, 1), e);

		    e.extendA();
		    Assert.AreEqual(new Edit(1, 4, 1, 1), e);
	    }