示例#1
0
        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 GetMatches_MatchWasNotCalled_EmptyListReturned()
        {
            var textMatcher = new TextMatcher("Not Important", "Not Important");

            var matches = textMatcher.GetMatches();

            Assert.True(matches.Count() == 0);
        }
示例#3
0
        public async Task Text_NoMatch()
        {
            var message = new Messages.Message();

            message.Text = "hello world";

            var matcher = new TextMatcher("test");
            var matches = await matcher.GetMatches(message);

            Assert.Null(matches);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
        public async Task Text_Match()
        {
            var message = new Messages.Message();

            message.Text = "hello world";

            var matcher = new TextMatcher("hello world");
            var matches = await matcher.GetMatches(message);

            Assert.Equal(1, matches.Length);
            Assert.Equal("hello world", matches[0].Text);
        }
示例#7
0
        private void buildMatchesMessage(TextMatcher textMatcher)
        {
            foreach (var match in textMatcher.GetMatches())
            {
                _matchesMessage.Append(match.StartPosition + ",");
            }

            if (_matchesMessage.Length > 0)
            {
                const int arrayOffset = 1;
                var lastCharacterPosition = _matchesMessage.Length - arrayOffset;
                const int numberOfCharacters = 1;
                _matchesMessage.Remove(lastCharacterPosition, numberOfCharacters);
            }
        }
            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);
                }

            }
            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);
                }

            }
示例#10
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);
            }





        }
示例#11
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);
        }
示例#12
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);   
        }
示例#13
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);            
        }
            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);
            }