예제 #1
0
        public void GapBuffer_RemoveTest()
        {
            GapBuffer <int> buf = CreateTestGapBuffer();

            Assert.IsFalse(buf.Remove(0));

            Assert.AreEqual(16, buf.IndexOf(999));
            Assert.IsTrue(buf.Remove(999));
            Assert.AreEqual(-1, buf.IndexOf(999));

            buf.RemoveAt(1);
            Assert.AreEqual(1, buf.Gap);

            buf.RemoveAt(0);
            Assert.AreEqual(23, buf.Count);
            Assert.AreEqual(0, buf.Gap);
            Assert.AreEqual(9, buf.GapCount);
            Assert.AreEqual(9, buf.AfterGap);

            buf.RemoveAt(21);
            Assert.AreEqual(21, buf.Gap);

            buf.RemoveAt(21);
            Assert.AreEqual(21, buf.Count);
            Assert.AreEqual(21, buf.Gap);
            Assert.AreEqual(11, buf.GapCount);
            Assert.AreEqual(32, buf.AfterGap);

            for (int i = 0; i < buf.Count; i++)
            {
                Assert.AreEqual(102 + i, buf[i]);
            }
        }
        public void TestSearchForwardMany()
        {
            GapBuffer buffer = new GapBuffer();

            buffer.Text = new string ('a', 100);
            int cnt = 0;
            int o   = 0;

            while ((o = buffer.IndexOf("a", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                cnt++;
                o++;
            }
            Assert.AreEqual(100, cnt);
        }
예제 #3
0
        public void GapBuffer_IndexOfTest()
        {
            GapBuffer <int> buf = CreateTestGapBuffer();

            Assert.AreEqual(0, buf.IndexOf(100));
            Assert.AreEqual(15, buf.IndexOf(115));
            Assert.AreEqual(17, buf.IndexOf(116));
            Assert.AreEqual(25, buf.IndexOf(124));
            Assert.AreEqual(-1, buf.IndexOf(125));
            Assert.AreEqual(16, buf.IndexOf(999));

            Assert.IsTrue(buf.Contains(100));
            Assert.IsTrue(buf.Contains(999));
            Assert.IsFalse(buf.Contains(0));
        }
예제 #4
0
 public void TestSearchForwardMany()
 {
     GapBuffer buffer = new GapBuffer ();
     buffer.Text = new string ('a', 100);
     int cnt = 0;
     int o = 0;
     while ((o = buffer.IndexOf ("a", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0) {
         cnt++;
         o++;
     }
     Assert.AreEqual (100, cnt);
 }
예제 #5
0
        public void TestSearchForwardIgnoreCase()
        {
            GapBuffer buffer = new GapBuffer ();
            for (int i = 0; i < 100; i++) {
                buffer.Insert (0, "a");
            }
            var idx = new List<int> (new [] { 0,  buffer.TextLength / 2, buffer.TextLength });

            idx.ForEach (i => buffer.Insert (i, "test"));

            // move gap to the beginning
            buffer.Replace (idx [0], 1, buffer.GetCharAt (idx [0]).ToString ());

            List<int> results = new List<int> ();
            int o = 0;
            while ((o = buffer.IndexOf ("TEST", o, buffer.TextLength - o, StringComparison.OrdinalIgnoreCase)) >= 0) {
                results.Add (o);
                o++;
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);

            // move gap to the middle
            buffer.Replace (idx [1], 1, buffer.GetCharAt (idx [1]).ToString ());

            results = new List<int> ();
            o = 0;
            while ((o = buffer.IndexOf ("TEST", o, buffer.TextLength - o, StringComparison.OrdinalIgnoreCase)) >= 0) {
                results.Add (o);
                o++;
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);

            // move gap to the end
            buffer.Replace (idx [2], 1, buffer.GetCharAt (idx [2]).ToString ());

            results = new List<int> ();
            o = 0;
            while ((o = buffer.IndexOf ("TEST", o, buffer.TextLength - o, StringComparison.OrdinalIgnoreCase)) >= 0) {
                results.Add (o);
                o++;
            }
            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);

            // move gap to the end
            buffer.Replace (buffer.TextLength - 1, 1, buffer.GetCharAt (buffer.TextLength - 1).ToString ());

            results = new List<int> ();
            o = 0;
            while ((o = buffer.IndexOf ("TEST", o, buffer.TextLength - o, StringComparison.OrdinalIgnoreCase)) >= 0) {
                results.Add (o);
                o++;
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
        }
        public void TestSearchForward()
        {
            GapBuffer buffer = new GapBuffer();

            for (int i = 0; i < 100; i++)
            {
                buffer.Insert(0, "a");
            }
            var idx = new List <int> (new [] { 0, buffer.TextLength / 2, buffer.TextLength });

            idx.ForEach(i => buffer.Insert(i, "test"));

            // move gap to the beginning
            buffer.Replace(idx [0], 1, buffer.GetCharAt(idx [0]).ToString());

            List <int> results = new List <int> ();

            int o = 0;

            while ((o = buffer.IndexOf("test", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                results.Add(o);
                o++;
            }


            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);
            }

            // move gap to the middle
            buffer.Replace(idx [1], 1, buffer.GetCharAt(idx [1]).ToString());

            results = new List <int> ();
            o       = 0;
            while ((o = buffer.IndexOf("test", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                results.Add(o);
                o++;
            }

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);
            }

            // move gap to the end
            buffer.Replace(idx [2], 1, buffer.GetCharAt(idx [2]).ToString());

            results = new List <int> ();
            o       = 0;
            while ((o = buffer.IndexOf("test", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                results.Add(o);
                o++;
            }

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);
            }

            // move gap to the end
            buffer.Replace(buffer.TextLength - 1, 1, buffer.GetCharAt(buffer.TextLength - 1).ToString());

            results = new List <int> ();
            o       = 0;
            while ((o = buffer.IndexOf("test", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                results.Add(o);
                o++;
            }

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[i], results[i], (i + 1) + ". match != " + idx[i] + " was " + results[i]);
            }
        }