Пример #1
0
        public void TestScanRunQueueMultipleTimes2()
        {
            //harder one
            int      callInc = 0;
            RunQueue rq2     = new RunQueue(5);

            FillRunQueue(rq2, GetTestRuns2());
            RunQueue rq2_clone = rq2.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.ScanQueuedRuns(rq2, "3",
                                 delegate(Run run, int index, int length)
            {
                Assert.IsTrue(callInc < 1);
                if (callInc == 0)
                {
                    Assert.AreEqual(rq2_clone[1].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(1, length);
                }
                callInc++;
            }
                                 );
            //add new item and search again, this time we don't want to hit 3 again
            rq2.Enqueue(new Run("3"));
            model.ScanQueuedRuns(rq2, "3",
                                 delegate(Run run, int index, int length)
            {
                Assert.AreEqual("3", run.Text);
            }
                                 );
        }
        public void MultipleIgnoresWithRuns()
        {
            List <Run> runs = new List <Run>();

            runs.Add(new Run("Some rich text box content"));
            runs.Add(new Run("some rich text bo"));
            runs.Add(new Run("55555 6666"));


            //harder one
            int      callInc = 0;
            RunQueue rq2     = new RunQueue(5);

            QueueTests.FillRunQueue(rq2, runs);
            RunQueue rq2_clone = rq2.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.IgnoreWhitespaceCharacters = true;
            model.ScanQueuedRuns(rq2, "some rich text box",
                                 delegate(Run run, int index, int length)
            {
                Assert.IsTrue(callInc < 1);
                if (callInc == 0)
                {
                    Assert.AreEqual(rq2_clone[0].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(18, length);
                }
                callInc++;
            }
                                 );
        }
Пример #3
0
        public void TestCrossRunMatch2()
        {
            RunQueue queue = new RunQueue(2);
            Run      r1 = new Run("1234co"), r2 = new Run("co5678");
            int      callInc = 0;

            queue.Enqueue(r1);
            queue.Enqueue(r2);
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.ScanQueuedRuns(queue, "coco",
                                 delegate(Run run, int index, int length)
            {
                Assert.IsTrue(callInc < 2);
                if (callInc == 0)
                {
                    Assert.AreEqual(r1, run);
                    Assert.AreEqual(4, index);
                    Assert.AreEqual(2, length);
                }
                else if (callInc == 1)
                {
                    Assert.AreEqual(r2, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(2, length);
                }
                callInc++;
            }
                                 );
            Assert.AreEqual(2, callInc);
        }
Пример #4
0
        public void MakeInvalid()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.UseRegularExpressions = true;
            Query q = new Query(".*[");
            RunQueue rq = new RunQueue(1);
            rq.Enqueue(new System.Windows.Documents.Run("hello this is it"));
            model.ScanQueuedRuns(rq, q, null);
            Assert.IsFalse(q.Valid);
            Assert.AreEqual("Regular expression error, parsing \".*[\" - Unterminated [] set.", q.ReasonInvalid);

        }
Пример #5
0
        public void TestScanRunQueueMultipleTimes3()
        {
            //harder one
            int      callInc = 0;
            RunQueue rq2     = new RunQueue(5);

            FillRunQueue(rq2, GetTestRuns2());

            rq2.Enqueue(new Run("3 3"));
            rq2.Enqueue(new Run("232"));
            RunQueue rq2_clone = rq2.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.ScanQueuedRuns(rq2, "3",
                                 delegate(Run run, int index, int length)
            {
                Assert.IsTrue(callInc < 4);
                if (callInc == 0)
                {
                    Assert.AreEqual(rq2_clone[1].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(1, length);
                }
                else if (callInc == 1)
                {
                    Assert.AreEqual(rq2_clone[3].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(1, length);
                }
                else if (callInc == 2)
                {
                    Assert.AreEqual(rq2_clone[3].Run, run);
                    Assert.AreEqual(2, index);
                    Assert.AreEqual(1, length);
                }
                else if (callInc == 3)
                {
                    Assert.AreEqual(rq2_clone[4].Run, run);
                    Assert.AreEqual(1, index);
                    Assert.AreEqual(1, length);
                }
                callInc++;
            }
                                 );
        }
        public void IgnoreWhitespaceSplitRuns()
        {
            List <Run> runs = new List <Run>();

            runs.Add(new Run("  a b"));
            runs.Add(new Run(" c"));
            runs.Add(new Run(" stella was here a b "));
            runs.Add(new Run("but not here"));
            runs.Add(new Run("ok she's back a b"));


            //harder one
            int      callInc = 0;
            RunQueue rq2     = new RunQueue(5);

            QueueTests.FillRunQueue(rq2, runs);
            RunQueue rq2_clone = rq2.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.IgnoreWhitespaceCharacters = true;
            model.ScanQueuedRuns(rq2, "abc",
                                 delegate(Run run, int index, int length)
            {
                Assert.IsTrue(callInc < 2);
                if (callInc == 0)
                {
                    Assert.AreEqual(rq2_clone[0].Run, run);
                    Assert.AreEqual(2, index);
                    Assert.AreEqual(3, length);
                }
                if (callInc == 1)
                {
                    Assert.AreEqual(rq2_clone[1].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(2, length);
                }
                callInc++;
            }
                                 );

            callInc = 0;
            model.ScanQueuedRuns(rq2, "a b c",
                                 delegate(Run run, int index, int length)
            {
                Assert.IsTrue(callInc < 2);
                if (callInc == 0)
                {
                    Assert.AreEqual(rq2_clone[0].Run, run);
                    Assert.AreEqual(2, index);
                    Assert.AreEqual(3, length);
                }
                if (callInc == 1)
                {
                    Assert.AreEqual(rq2_clone[1].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(2, length);
                }
                callInc++;
            }
                                 );
        }
Пример #7
0
        public void TestScanRunQueue()
        {
            RunQueue rq = new RunQueue(5);

            FillRunQueue(rq, GetTestRuns());

            RunQueue rq_clone = rq.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            //easy one
            model.ScanQueuedRuns(rq, new Keyoti.RapidFindReplace.WPF.Query("1111"),
                                 delegate(Run run, int index, int length){
                Assert.AreEqual(rq_clone[0].Run, run);
                Assert.AreEqual(0, index);
                Assert.AreEqual(4, length);
            }
                                 );

            //easy one
            model.ScanQueuedRuns(rq, "4444",
                                 delegate(Run run, int index, int length)
            {
                Assert.AreEqual(rq_clone[1].Run, run);
                Assert.AreEqual(5, index);
                Assert.AreEqual(4, length);
            }
                                 );

            //harder one
            int callInc = 0;

            model.ScanQueuedRuns(rq, "44445555",
                                 delegate(Run run, int index, int length)
            {
                if (callInc == 0)
                {
                    Assert.AreEqual(rq_clone[1].Run, run);
                    Assert.AreEqual(5, index);
                    Assert.AreEqual(4, length);
                }
                else if (callInc == 1)
                {
                    Assert.AreEqual(rq_clone[2].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(4, length);
                }
                callInc++;
            }
                                 );

            //harder one
            callInc = 0;
            RunQueue rq2 = new RunQueue(5);

            FillRunQueue(rq2, GetTestRuns2());
            RunQueue rq2_clone = rq2.Clone();

            model.ScanQueuedRuns(rq2, "22223",
                                 delegate(Run run, int index, int length)
            {
                if (callInc == 0)
                {
                    Assert.AreEqual(rq2_clone[0].Run, run);
                    Assert.AreEqual(2, index);
                    Assert.AreEqual(4, length);
                }
                else if (callInc == 1)
                {
                    Assert.AreEqual(rq2_clone[1].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(1, length);
                }

                Assert.IsTrue(callInc < 2);
                callInc++;
            }
                                 );
        }