Example #1
0
        public virtual void TestComparatorReduceCommonStartEnd()
        {
            RawTextComparator c = RawTextComparator.DEFAULT;
            Edit e;

            e = c.ReduceCommonStartEnd(T(string.Empty), T(string.Empty), new Edit(0, 0, 0, 0)
                                       );
            NUnit.Framework.Assert.AreEqual(new Edit(0, 0, 0, 0), e);
            e = c.ReduceCommonStartEnd(T("a"), T("b"), new Edit(0, 1, 0, 1));
            NUnit.Framework.Assert.AreEqual(new Edit(0, 1, 0, 1), e);
            e = c.ReduceCommonStartEnd(T("a"), T("a"), new Edit(0, 1, 0, 1));
            NUnit.Framework.Assert.AreEqual(new Edit(1, 1, 1, 1), e);
            e = c.ReduceCommonStartEnd(T("axB"), T("axC"), new Edit(0, 3, 0, 3));
            NUnit.Framework.Assert.AreEqual(new Edit(2, 3, 2, 3), e);
            e = c.ReduceCommonStartEnd(T("Bxy"), T("Cxy"), new Edit(0, 3, 0, 3));
            NUnit.Framework.Assert.AreEqual(new Edit(0, 1, 0, 1), e);
            e = c.ReduceCommonStartEnd(T("bc"), T("Abc"), new Edit(0, 2, 0, 3));
            NUnit.Framework.Assert.AreEqual(new Edit(0, 0, 0, 1), e);
            e = new Edit(0, 5, 0, 5);
            e = c.ReduceCommonStartEnd(T("abQxy"), T("abRxy"), e);
            NUnit.Framework.Assert.AreEqual(new Edit(2, 3, 2, 3), e);
            RawText a = new RawText(Sharpen.Runtime.GetBytesForString("p\na b\nQ\nc d\n", "UTF-8"
                                                                      ));
            RawText b = new RawText(Sharpen.Runtime.GetBytesForString("p\na  b \nR\n c  d \n"
                                                                      , "UTF-8"));

            e = new Edit(0, 4, 0, 4);
            e = RawTextComparator.WS_IGNORE_ALL.ReduceCommonStartEnd(a, b, e);
            NUnit.Framework.Assert.AreEqual(new Edit(2, 3, 2, 3), e);
        }
Example #2
0
        public virtual void TestEquals()
        {
            RawText           a   = new RawText(Constants.EncodeASCII("foo-a\nfoo-b\n"));
            RawText           b   = new RawText(Constants.EncodeASCII("foo-b\nfoo-c\n"));
            RawTextComparator cmp = RawTextComparator.DEFAULT;

            NUnit.Framework.Assert.AreEqual(2, a.Size());
            NUnit.Framework.Assert.AreEqual(2, b.Size());
            // foo-a != foo-b
            NUnit.Framework.Assert.IsFalse(cmp.Equals(a, 0, b, 0));
            NUnit.Framework.Assert.IsFalse(cmp.Equals(b, 0, a, 0));
            // foo-b == foo-b
            NUnit.Framework.Assert.IsTrue(cmp.Equals(a, 1, b, 0));
            NUnit.Framework.Assert.IsTrue(cmp.Equals(b, 0, a, 1));
        }
Example #3
0
        public virtual void TestFallbackToMyersDiff()
        {
            HistogramDiff hd = new HistogramDiff();

            hd.SetMaxChainLength(4);
            RawTextComparator cmp = RawTextComparator.DEFAULT;
            RawText           ac  = T("bbbbb");
            RawText           bc  = T("AbCbDbEFbZ");
            EditList          r;

            // Without fallback our results are limited due to collisions.
            hd.SetFallbackAlgorithm(null);
            r = hd.Diff(cmp, ac, bc);
            NUnit.Framework.Assert.AreEqual(1, r.Count);
            // Results go up when we add a fallback for the high collision regions.
            hd.SetFallbackAlgorithm(MyersDiff <Sequence> .INSTANCE);
            r = hd.Diff(cmp, ac, bc);
            NUnit.Framework.Assert.AreEqual(5, r.Count);
        }
Example #4
0
 /// <summary>Set the line equivalence function for text file differences.</summary>
 /// <remarks>Set the line equivalence function for text file differences.</remarks>
 /// <param name="cmp">
 /// The equivalence function used to determine if two lines of
 /// text are identical. The function can be changed to ignore
 /// various types of whitespace.
 /// </param>
 /// <seealso cref="RawTextComparator.DEFAULT">RawTextComparator.DEFAULT</seealso>
 /// <seealso cref="RawTextComparator.WS_IGNORE_ALL">RawTextComparator.WS_IGNORE_ALL</seealso>
 /// <seealso cref="RawTextComparator.WS_IGNORE_CHANGE">RawTextComparator.WS_IGNORE_CHANGE
 ///     </seealso>
 /// <seealso cref="RawTextComparator.WS_IGNORE_LEADING">RawTextComparator.WS_IGNORE_LEADING
 ///     </seealso>
 /// <seealso cref="RawTextComparator.WS_IGNORE_TRAILING">RawTextComparator.WS_IGNORE_TRAILING
 ///     </seealso>
 public virtual void SetDiffComparator(RawTextComparator cmp)
 {
     comparator = cmp;
 }