コード例 #1
0
ファイル: MainController.cs プロジェクト: gbarrs/.NET-Scratch
        public MainView DoTextMatch(string text, string subtext)
        {
            try
            {
                reset();

                if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(subtext))
                {
                    createInputEmptyMatchView(text, subtext);
                    return _mainView;
                }

                var textMatcher = new TextMatcher(text, subtext);
                textMatcher.Match();

                if (textMatcher.GetMatches().Count() == 0)
                {
                    createNoMatchView(text, subtext);
                    return _mainView;
                }

                createMatchView(text, subtext, textMatcher);
                return _mainView;

            }
            catch (SubtextLongerThanTextException)
            {

                createSubtextTooLongMatchView(text, subtext);
                return _mainView;
            }

        }
コード例 #2
0
        public void Match_TextContainsThreeInstancesOfSingleCharacterSubtext_ListContainsThreeMatches()
        {
            const string text = "abcabcabc";
            const string subtext = "a";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();

            Assert.True(matches.Count() == 3);
        }
コード例 #3
0
        public void Match_TextContainsOneInstanceOfSingleCharacterSubtext_MatchHasCorrectStartPosition()
        {
            const string text = "abc";
            const string subtext = "a";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();

            Assert.True(matches.First().StartPosition == 1);
        }
コード例 #4
0
            public void Then_the_output_should_be_3_28_53_78_82()
            {

                const string subtext = "ll";
                var output = new[] { 3, 28, 53, 78, 82 };

                var textMatcher = new TextMatcher(_text, subtext);
                textMatcher.Match();

                var matches = textMatcher.GetMatches();
                matches.should_have_count(5);
                foreach (var match in matches)
                {
                    output.should_contain(match.StartPosition);
                }

            }
コード例 #5
0
            public void Then_the_output_should_be_1_26_51()
            {

                const string subtext = "polly";
                var output = new[] { 1, 26, 51 };

                var textMatcher = new TextMatcher(_text, subtext);
                textMatcher.Match();

                var matches = textMatcher.GetMatches();
                matches.should_have_count(3);
                foreach (var match in matches)
                {
                    output.should_contain(match.StartPosition);
                }

            }
コード例 #6
0
        public void Match_TextContainsThreeInstancesOfSingleCharacterSubtext_MatchesHaveCorrectStartPositions()
        {
            const string text = "abcabcabc";
            const string subtext = "a";
            var output = new[] { 1, 4, 7 };
            

            var textMatcher = new TextMatcher(text, subtext);
            textMatcher.Match();
            
            var matches = textMatcher.GetMatches();
            const int outputNotFoundValue = 0;
            foreach (int foundInOutput in matches.Select(match => (from o in output
                                                                         where o == match.StartPosition
                                                                         select o).SingleOrDefault()))
            {                
                Assert.AreNotEqual(outputNotFoundValue,foundInOutput);
            }





        }
コード例 #7
0
        public void Match_AttemptToMatchPastLastCharacterOfText_ListContainsNoMatches()
        {
            const string text = "abcxyzabc";
            const string subtext = "ccc";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();
            matches.Count().should_equal(0);
        }
コード例 #8
0
        public void Match_UpperCaseTextContainsOneInstanceOfLowerCaseSubtext_CaseInsensitiveMatchOccurs()
        {
            const string text = "abcXYZabc";
            const string subtext = "xyz";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();

            Assert.True(matches.First().StartPosition == 4);   
        }
コード例 #9
0
        public void Match_TextContainsOneInstanceOfMultiCharacterSubtext_ListContainsOneMatch()
        {
            const string text = "abcxyzabc";
            const string subtext = "xyz";
            var textMatcher = new TextMatcher(text, subtext);

            textMatcher.Match();
            var matches = textMatcher.GetMatches();

            Assert.True(matches.Count() == 1);            
        }
コード例 #10
0
            public void Then_there_should_be_no_matches()
            {

                const string subtext = "aaa";

                var textMatcher = new TextMatcher(_text, subtext);
                textMatcher.Match();

                var matches = textMatcher.GetMatches();
                matches.should_have_count(0);
            }