Exemplo n.º 1
0
		public virtual void TestAddOne()
		{
			Edit e = new Edit(1, 2, 1, 1);
			EditList l = new EditList();
			l.AddItem(e);
			NUnit.Framework.Assert.AreEqual(1, l.Count);
			NUnit.Framework.Assert.IsFalse(l.IsEmpty());
			NUnit.Framework.Assert.AreSame(e, l[0]);
			NUnit.Framework.Assert.AreSame(e, l.Iterator().Next());
			NUnit.Framework.Assert.AreEqual(l, l);
			NUnit.Framework.Assert.IsFalse(l.Equals(new EditList()));
			EditList l2 = new EditList();
			l2.AddItem(e);
			NUnit.Framework.Assert.AreEqual(l2, l);
			NUnit.Framework.Assert.AreEqual(l, l2);
			NUnit.Framework.Assert.AreEqual(l.GetHashCode(), l2.GetHashCode());
		}
Exemplo n.º 2
0
        /// <returns>a list describing the content edits performed within the hunk.</returns>
        public virtual EditList ToEditList()
        {
            if (editList == null)
            {
                editList = new EditList();
                byte[] buf = file.buf;
                int c = RawParseUtils.NextLF(buf, startOffset);
                int oLine = old.startLine;
                int nLine = newStartLine;
                Edit @in = null;
                for (; c < endOffset; c = RawParseUtils.NextLF(buf, c))
                {
                    switch (buf[c])
                    {
                        case (byte)(' '):
                        case (byte)('\n'):
                        {
                            @in = null;
                            oLine++;
                            nLine++;
                            continue;
                            goto case (byte)('-');
                        }

                        case (byte)('-'):
                        {
                            if (@in == null)
                            {
                                @in = new Edit(oLine - 1, nLine - 1);
                                editList.AddItem(@in);
                            }
                            oLine++;
                            @in.ExtendA();
                            continue;
                            goto case (byte)('+');
                        }

                        case (byte)('+'):
                        {
                            if (@in == null)
                            {
                                @in = new Edit(oLine - 1, nLine - 1);
                                editList.AddItem(@in);
                            }
                            nLine++;
                            @in.ExtendB();
                            continue;
                            goto case (byte)('\\');
                        }

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

                        default:
                        {
                            goto SCAN_break;
                            break;
                        }
                    }
            SCAN_continue: ;
                }
            SCAN_break: ;
            }
            return editList;
        }
Exemplo n.º 3
0
        /// <returns>a list describing the content edits performed within the hunk.</returns>
        public virtual EditList ToEditList()
        {
            if (editList == null)
            {
                editList = new EditList();
                byte[] buf   = file.buf;
                int    c     = RawParseUtils.NextLF(buf, startOffset);
                int    oLine = old.startLine;
                int    nLine = newStartLine;
                Edit   @in   = null;
                for (; c < endOffset; c = RawParseUtils.NextLF(buf, c))
                {
                    switch (buf[c])
                    {
                    case (byte)(' '):
                    case (byte)('\n'):
                    {
                        @in = null;
                        oLine++;
                        nLine++;
                        continue;
                        goto case (byte)('-');
                    }

                    case (byte)('-'):
                    {
                        if (@in == null)
                        {
                            @in = new Edit(oLine - 1, nLine - 1);
                            editList.AddItem(@in);
                        }
                        oLine++;
                        @in.ExtendA();
                        continue;
                        goto case (byte)('+');
                    }

                    case (byte)('+'):
                    {
                        if (@in == null)
                        {
                            @in = new Edit(oLine - 1, nLine - 1);
                            editList.AddItem(@in);
                        }
                        nLine++;
                        @in.ExtendB();
                        continue;
                        goto case (byte)('\\');
                    }

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

                    default:
                    {
                        goto SCAN_break;
                        break;
                    }
                    }
                    SCAN_continue :;
                }
                SCAN_break :;
            }
            return(editList);
        }
Exemplo n.º 4
0
		public virtual void TestAddTwo()
		{
			Edit e1 = new Edit(1, 2, 1, 1);
			Edit e2 = new Edit(8, 8, 8, 12);
			EditList l = new EditList();
			l.AddItem(e1);
			l.AddItem(e2);
			NUnit.Framework.Assert.AreEqual(2, l.Count);
			NUnit.Framework.Assert.AreSame(e1, l[0]);
			NUnit.Framework.Assert.AreSame(e2, l[1]);
			Iterator<Edit> i = l.Iterator();
			NUnit.Framework.Assert.AreSame(e1, i.Next());
			NUnit.Framework.Assert.AreSame(e2, i.Next());
			NUnit.Framework.Assert.AreEqual(l, l);
			NUnit.Framework.Assert.IsFalse(l.Equals(new EditList()));
			EditList l2 = new EditList();
			l2.AddItem(e1);
			l2.AddItem(e2);
			NUnit.Framework.Assert.AreEqual(l2, l);
			NUnit.Framework.Assert.AreEqual(l, l2);
			NUnit.Framework.Assert.AreEqual(l.GetHashCode(), l2.GetHashCode());
		}
Exemplo n.º 5
0
		public virtual void TestRemove()
		{
			Edit e1 = new Edit(1, 2, 1, 1);
			Edit e2 = new Edit(8, 8, 8, 12);
			EditList l = new EditList();
			l.AddItem(e1);
			l.AddItem(e2);
			l.Remove(e1);
			NUnit.Framework.Assert.AreEqual(1, l.Count);
			NUnit.Framework.Assert.AreSame(e2, l[0]);
		}
Exemplo n.º 6
0
		public virtual void TestSet()
		{
			Edit e1 = new Edit(1, 2, 1, 1);
			Edit e2 = new Edit(3, 4, 3, 3);
			EditList l = new EditList();
			l.AddItem(e1);
			NUnit.Framework.Assert.AreSame(e1, l[0]);
			NUnit.Framework.Assert.AreSame(e1, l.Set(0, e2));
			NUnit.Framework.Assert.AreSame(e2, l[0]);
		}