示例#1
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);
        }
示例#2
0
        public void OptionFlipping()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.Query = new Query("some more");
            model.FindOptions.IgnoreWhitespaceCharacters = false;
            List <Run> runs = new List <Run>();

            runs.Add(new Run("some more"));
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);

            model.FindText(container);
            model.SelectNextMatch();
            Assert.AreEqual(model.CurrentMatch.AbsoluteEnd, 9);
            Assert.AreEqual(model.CurrentMatch.AbsoluteStart, 0);



            model.FindOptions.IgnoreWhitespaceCharacters = true;
            model.FindOptions.IgnoreWhitespaceCharacters = false;

            model.Query.QueryText = "some more ";
            model.FindText(container);
            model.SelectNextMatch();


            model.Query.QueryText = "some more";
            model.FindText(container);
            model.SelectNextMatch();
            Assert.AreEqual(model.CurrentMatch.AbsoluteEnd, 9);
            Assert.AreEqual(model.CurrentMatch.AbsoluteStart, 0);
        }
示例#3
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);
            }
                                 );
        }
示例#4
0
        public void Match_Wildcard_WithIgnoreWhitespace()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.FindWholeWordsOnly          = false;
            model.FindOptions.IgnorePunctuationCharacters = false;
            model.FindOptions.IgnoreWhitespaceCharacters  = true;
            model.FindOptions.MatchCase             = false;
            model.FindOptions.MatchPrefix           = false;
            model.FindOptions.MatchSuffix           = false;
            model.FindOptions.UseWildcards          = true;
            model.FindOptions.UseRegularExpressions = false;

            Hit    match;
            string testText = "this     was some text";

            match = model.GetNextMatch_FOR_TESTING("th*s was", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(12, match.Length);

            testText = "this   was some text";

            match = model.GetNextMatch_FOR_TESTING("this w*s", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(10, match.Length);
        }
        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++;
            }
                                 );
        }
示例#6
0
        public void Match_Wildcard_Replace()
        {
            List <Run> runs = new List <Run>();

            runs.Add(new Run("1aa1 2222 1aa1"));
            runs.Add(new Run("3333 4444"));
            runs.Add(new Run("5555 6666"));
            runs.Add(new Run("7777 8888"));
            runs.Add(new Run("9999 aaaa"));

            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.UseWildcards = true;
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            model.Query = new Query("1*1");
            model.FindText(container /*, new Query("33([0-9])3")*/);


            model.SelectNextMatch();
            Assert.AreEqual("1aa1", model.CurrentMatch.Text);
            Assert.AreEqual(runs[0], model.CurrentMatch.Run);
            model.ReplaceMatch("abcdefg");

            Assert.AreEqual("abcdefg 2222 1aa1", runs[0].Text);


            Assert.AreEqual(runs[0], model.CurrentMatch.Run);
            model.ReplaceMatch("abcdefg");
            Assert.AreEqual("abcdefg 2222 abcdefg", runs[0].Text);
        }
示例#7
0
        public void Match_Wildcard_WithIgnorePunctuation()//problem is ignore punct will destroy the wildacard in the query, could just not strip it in query??
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.FindWholeWordsOnly          = false;
            model.FindOptions.IgnorePunctuationCharacters = true;
            model.FindOptions.IgnoreWhitespaceCharacters  = false;
            model.FindOptions.MatchCase             = false;
            model.FindOptions.MatchPrefix           = false;
            model.FindOptions.MatchSuffix           = false;
            model.FindOptions.UseWildcards          = true;
            model.FindOptions.UseRegularExpressions = false;

            Hit    match;
            string testText = "this 'was some text";

            //Because we cannot remove punct from the query when the match is wildcard or regex, we have to search without it.
            match = model.GetNextMatch_FOR_TESTING("th*s was", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(9, match.Length);

            //Because we cannot remove punct from the query when the match is wildcard or regex, we have to search without it.
            match = model.GetNextMatch_FOR_TESTING("this was", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(9, match.Length);
        }
示例#8
0
        public void Match_Wildcard_Replace2()
        {
            List <Run> runs = new List <Run>();

            runs.Add(new Run("TextBox search word"));
            runs.Add(new Run("TextBox"));
            runs.Add(new Run("TextBox"));
            runs.Add(new Run("Hello"));
            runs.Add(new Run("here is some more"));
            runs.Add(new Run("and some more"));

            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.UseWildcards = true;
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            model.Query = new Query("r*");
            model.FindText(container);


            model.SelectNextMatch();
            Assert.AreEqual("r", model.CurrentMatch.Text);
            Assert.AreEqual(runs[0], model.CurrentMatch.Run);
            //model.ReplaceMatch("   ");
            model.ReplaceAllMatches("   ");

            Assert.AreEqual("TextBox sea   ch wo   d", runs[0].Text);
        }
示例#9
0
        public void Match_Blend_WholeWords_Wildcards()
        {
            //should essentially match whole words only
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.FindWholeWordsOnly          = true;
            model.FindOptions.IgnorePunctuationCharacters = false;
            model.FindOptions.IgnoreWhitespaceCharacters  = false;
            model.FindOptions.MatchCase    = false;
            model.FindOptions.MatchPrefix  = false;
            model.FindOptions.MatchSuffix  = false;
            model.FindOptions.UseWildcards = true;



            Hit    match;
            string testText = "this was some text";

            match = model.GetNextMatch_FOR_TESTING("th*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th*a", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);
        }
 private void _searchTextBox_KeyUp(object sender, KeyEventArgs e)
 {
     if (cb1.IsChecked == true)
     {
         RapidFindReplaceControlViewModel viewModel = _searchTextBox.DataContext as RapidFindReplaceControlViewModel;
         viewModel.FindText(viewModel.FindScope);
     }
 }
示例#11
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);

        }
        public void FlowProblem_Jimmy_SecondColumn_no2()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            FlowDocument content  = LoadFlowDocument("FlowDocument4.xaml");
            int          hitCount = 0;

            finder.FindTextIn(new FlowDocumentRunReader(content), delegate(Run run, int index, int length)
            {
                hitCount++;
            }, new Query("jimmy"));

            Assert.AreEqual(2, hitCount);
        }
        public void FlowProblem1_AsFlowDocument_WithRegistry()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            bool         hit     = false;
            FlowDocument content = LoadFlowDocument("FlowDocument1.xaml");

            finder.FindTextIn(FindHandlerRegistry.CreateIRunReaderHandlerFor(content), delegate(Run run, int index, int length)
            {
                hit = true;
            }, new Query("urna jimmy"));

            Assert.IsTrue(hit);
        }
        public void Flow_3()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            // finder.FindOptions.IgnoreWhitespaceCharacters = true;
            bool         hit     = false;
            FlowDocument content = LoadFlowDocument("FlowDocument3.xaml");

            finder.FindTextIn(FindHandlerRegistry.CreateIRunReaderHandlerFor(content), delegate(Run run, int index, int length)
            {
                hit = true;
            }, new Query("a b c"));

            Assert.IsTrue(hit);
        }
        public void FlowProblem1()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            bool         hit     = false;
            FlowDocument content = LoadFlowDocument("FlowDocument1.xaml");

            System.Collections.Generic.List <Run> runs = new System.Collections.Generic.List <Run>(5);
            FindRuns(content.Blocks, runs);
            finder.FindTextIn(runs, delegate(Run run, int index, int length)
            {
                hit = true;
            }, new Query("urna jimmy"));

            Assert.IsTrue(hit);
        }
        public void PunctuationIgnorer_FromModel()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.FindWholeWordsOnly          = false;
            model.FindOptions.IgnorePunctuationCharacters = true;



            Hit    match;
            string testText = "this was-nt some text";

            match = model.GetNextMatch_FOR_TESTING("was-nt", 0, testText);
            Assert.AreEqual(5, match.Start);
            Assert.AreEqual(6, match.Length);
        }
示例#17
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++;
            }
                                 );
        }
示例#18
0
        public void Match_ReplaceAll()
        {
            List <Run> runs = new List <Run>();

            runs.Add(new Run("aa aa aa"));

            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            container.IterationStartIndex = 3;// runs[0].Text.Length - 1;
            model.Query = new Query("aa");
            model.FindText(container /*, new Query("33([0-9])3")*/);

            model.ReplaceAllMatches("bb");


            Assert.AreEqual("bb bb bb", runs[0].Text);
        }
示例#19
0
        public void Match_Regex_Replace()
        {
            List <Run> runs = GetTestRuns();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.UseRegularExpressions = true;
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            model.Query = new Query("33([0-9])3");
            model.FindText(container /*, new Query("33([0-9])3")*/);


            model.SelectNextMatch();
            Assert.AreEqual(runs[1], model.CurrentMatch.Run);
            model.ReplaceMatch("xx$1");

            Assert.AreEqual("xx3 4444", runs[1].Text);

            //also need to fix single line tb when highlight goes outside of box width
        }
        public void ReplaceAsFindWithPrependSpace()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();


            System.Collections.Generic.List <Run> runs = new System.Collections.Generic.List <Run>(5);
            //FindRuns(content.Blocks, runs);
            runs.Add(new Run("ax  ax"));
            runs.Add(new Run("T"));

            RunCollectionContainer coll = new RunCollectionContainer(runs);


            finder.Query = new Query("ax");
            finder.FindText(coll);



            finder.ReplaceAllMatchesCommand.Execute(" ax");
        }
        public void ReplaceReplaceAllProblem1()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            FlowDocument content = LoadFlowDocument("FlowDocument1.xaml");

            System.Collections.Generic.List <Run> runs = new System.Collections.Generic.List <Run>(5);
            //FindRuns(content.Blocks, runs);
            runs.Add(new Run("aaaa"));

            RunCollectionContainer coll = new RunCollectionContainer(runs);


            finder.Query = new Query("aaaa");
            finder.FindText(coll);



            finder.ReplaceMatchCommand.Execute("ddd");
            finder.ReplaceAllMatchesCommand.Execute("ddd");
        }
示例#22
0
        public void Match_Regex_WithIgnorePunctuation()//problem is ignore punct will destroy the regex in the query, could just not strip it in query??
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.FindWholeWordsOnly          = false;
            model.FindOptions.IgnorePunctuationCharacters = true;
            model.FindOptions.IgnoreWhitespaceCharacters  = false;
            model.FindOptions.MatchCase             = false;
            model.FindOptions.MatchPrefix           = false;
            model.FindOptions.MatchSuffix           = false;
            model.FindOptions.UseWildcards          = false;
            model.FindOptions.UseRegularExpressions = true;

            Hit    match;
            string testText = "this 'was some text";

            match = model.GetNextMatch_FOR_TESTING("th.* was", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(9, match.Length);
        }
        public void FindDoubleSpace()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();

            System.Collections.Generic.List <Run> runs = new System.Collections.Generic.List <Run>(5);
            //FindRuns(content.Blocks, runs);
            runs.Add(new Run("a  a"));
            runs.Add(new Run("T"));

            RunCollectionContainer coll = new RunCollectionContainer(runs);


            finder.Query = new Query("  ");
            finder.FindText(coll);

            finder.SelectNextMatch();


            Assert.AreEqual(1, finder.CurrentMatch.AbsoluteStart);
            Assert.AreEqual(3, finder.CurrentMatch.AbsoluteEnd);
        }
示例#24
0
        public void Match_Simple_CaseSensitive()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.FindWholeWordsOnly          = false;
            model.FindOptions.IgnorePunctuationCharacters = false;
            model.FindOptions.IgnoreWhitespaceCharacters  = false;
            model.FindOptions.MatchCase    = true;
            model.FindOptions.MatchPrefix  = false;
            model.FindOptions.MatchSuffix  = false;
            model.FindOptions.UseWildcards = false;



            Assert.AreEqual(-1, model.GetNextMatch_FOR_TESTING("xxx", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING("text", 0, "this is some text").Start);
            Assert.AreEqual(-1, model.GetNextMatch_FOR_TESTING("Text", 0, "this is some text").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("this", 0, "this is some text").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("this is some text", 0, "this is some text").Start);

            Assert.AreEqual(-1, model.GetNextMatch_FOR_TESTING("Text", 0, "this is some TEXT").Start);
        }
示例#25
0
        public void Match_Standard_Replace()
        {
            List <Run> runs = GetTestRuns();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            model.Query = new Query("1111");
            model.FindText(container /*, new Query("33([0-9])3")*/);


            model.SelectNextMatch();
            Assert.AreEqual(runs[0], model.CurrentMatch.Run);
            model.ReplaceMatch("1");

            Assert.AreEqual("1 2222 1111", runs[0].Text);

            model.ReplaceMatch("1");

            Assert.AreEqual("1 2222 1", runs[0].Text);

            //also need to fix single line tb when highlight goes outside of box width
        }
示例#26
0
        public void Match_Blend_WholeWords_Prefix()
        {
            //should essentially match whole words only
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.FindWholeWordsOnly          = true;
            model.FindOptions.IgnorePunctuationCharacters = false;
            model.FindOptions.IgnoreWhitespaceCharacters  = false;
            model.FindOptions.MatchCase    = false;
            model.FindOptions.MatchPrefix  = true;
            model.FindOptions.MatchSuffix  = false;
            model.FindOptions.UseWildcards = false;



            Assert.AreEqual(-1, model.GetNextMatch_FOR_TESTING("xxx", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING("text", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING("Text", 0, "this is some text").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("this", 0, "this is some text").Start);
            Assert.AreEqual(-1, model.GetNextMatch_FOR_TESTING("thi", 0, "this is some text").Start);
            Assert.AreEqual(8, model.GetNextMatch_FOR_TESTING("thi", 0, "this is thi thi").Start);
            Assert.AreEqual(12, model.GetNextMatch_FOR_TESTING("thi", 9, "this is thi thi").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("this is some text", 0, "this is some text").Start);
        }
示例#27
0
        public void Match_Regex()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.FindOptions.FindWholeWordsOnly          = false;
            model.FindOptions.IgnorePunctuationCharacters = false;
            model.FindOptions.IgnoreWhitespaceCharacters  = false;
            model.FindOptions.MatchCase             = false;
            model.FindOptions.MatchPrefix           = false;
            model.FindOptions.MatchSuffix           = false;
            model.FindOptions.UseWildcards          = false;
            model.FindOptions.UseRegularExpressions = true;

            Hit    match;
            string testText = "this was some text";

            match = model.GetNextMatch_FOR_TESTING("th.*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th.*", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th.*xt", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            match = model.GetNextMatch_FOR_TESTING("t.*xt", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th.*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING("xt.*a", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);

            match = model.GetNextMatch_FOR_TESTING(".*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING(".*.*.*", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);



            testText = "this was some text\r\nxxxx yyy";


            //Go with VS behaviour, which is !SingleLine mode (ie . cannot eat \n)
            match = model.GetNextMatch_FOR_TESTING("text.*yyy", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);


            testText = "This was SOME text\r\nxxxx yyy";

            model.FindOptions.MatchCase = true;
            match = model.GetNextMatch_FOR_TESTING("th[a-z]s", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);

            model.FindOptions.MatchCase = true;
            match = model.GetNextMatch_FOR_TESTING("Th[a-z]s", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(4, match.Length);

            model.FindOptions.MatchCase = true;
            match = model.GetNextMatch_FOR_TESTING("S.*E", 0, testText);
            Assert.AreEqual(9, match.Start);
            Assert.AreEqual(4, match.Length);
        }
示例#28
0
        public void TestHistoryQueue()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();

            model.QueryHistoryCapacity = 5;
            Assert.AreEqual(0, model.QueryHistory.Count);


            model.AddQueryToHistory("t1");
            Assert.AreEqual(1, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t1" }));

            model.AddQueryToHistory("t2");
            Assert.AreEqual(2, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t2", "t1" }));

            model.AddQueryToHistory("t3");
            Assert.AreEqual(3, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t3", "t2", "t1" }));

            model.AddQueryToHistory("t4");
            Assert.AreEqual(4, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t4", "t3", "t2", "t1" }));

            model.AddQueryToHistory("t5");
            Assert.AreEqual(5, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t5", "t4", "t3", "t2", "t1" }));

            model.AddQueryToHistory("t6");
            Assert.AreEqual(5, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t6", "t5", "t4", "t3", "t2" }));

            model.QueryHistoryCapacity = 3;
            Assert.AreEqual(3, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t6", "t5", "t4" }));

            model.AddQueryToHistory("t7");
            Assert.AreEqual(3, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t7", "t6", "t5" }));

            model.QueryHistoryCapacity = 6;
            Assert.AreEqual(3, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t7", "t6", "t5" }));

            model.AddQueryToHistory("t8");
            Assert.AreEqual(4, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t8", "t7", "t6", "t5" }));

            model.AddQueryToHistory("t9");
            Assert.AreEqual(5, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t9", "t8", "t7", "t6", "t5" }));

            model.AddQueryToHistory("t10");
            Assert.AreEqual(6, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t10", "t9", "t8", "t7", "t6", "t5" }));

            model.AddQueryToHistory("t11");
            Assert.AreEqual(6, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t11", "t10", "t9", "t8", "t7", "t6" }));


            model.QueryHistoryCapacity = 0;
            Assert.AreEqual(0, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] {  }));

            model.AddQueryToHistory("t11");
            Assert.AreEqual(0, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] {  }));
        }
        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++;
            }
                                 );
        }
示例#30
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++;
            }
                                 );
        }