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