public void ShouldNotMatchInvalidInputs(string input) { int expectedCount = 0; var plugin = new KarmaPlugin(); var matches = plugin.GetOperatorMatchesInMessage(input); int numberOfMatches = matches.Count; Assert.Equal(expectedCount, numberOfMatches); }
public void ShouldMatchValidInputs(string input, string expectedMatch) { int expected = 1; var plugin = new KarmaPlugin(); var matches = plugin.GetOperatorMatchesInMessage(input); int numberOfMatches = matches.Count; Assert.Equal(expected, numberOfMatches); Assert.Equal(expectedMatch, matches[0].Value); }
public void GivenWhitespace_ShouldOnlyMatchCharacters() { int expectedCount = 1; var expectedMatchvalue = "test++"; var plugin = new KarmaPlugin(); var matches = plugin.GetOperatorMatchesInMessage(" test++ "); int numberOfMatches = matches.Count; Assert.Equal(expectedCount, numberOfMatches); Assert.Equal(expectedMatchvalue, matches[0].Value); }
public void GivenHyphenatedPhrase_ShouldTreatNormally() { int expectedCount = 2; var expectedMatchvalueOne = "hyphenated-word--"; var expectedMatchvalueTwo = "part-time-teachers++"; var plugin = new KarmaPlugin(); var matches = plugin.GetOperatorMatchesInMessage("hyphenated-word-- part-time-teachers++"); int numberOfMatches = matches.Count; Assert.Equal(expectedCount, numberOfMatches); Assert.Equal(expectedMatchvalueOne, matches[0].Value); Assert.Equal(expectedMatchvalueTwo, matches[1].Value); }
public void GivenAdditionalPlusesOrMinnuses_ShouldMatchOnlyTwo() { int expectedCount = 4; var expectedMatchvalueOne = "test++"; var expectedMatchvalueTwo = "test--"; var plugin = new KarmaPlugin(); var matches = plugin.GetOperatorMatchesInMessage("test+++ test++++++++++ test--- test----------"); int numberOfMatches = matches.Count; Assert.Equal(expectedCount, numberOfMatches); Assert.Equal(expectedMatchvalueOne, matches[0].Value); Assert.Equal(expectedMatchvalueOne, matches[1].Value); Assert.Equal(expectedMatchvalueTwo, matches[2].Value); Assert.Equal(expectedMatchvalueTwo, matches[3].Value); }
private async IAsyncEnumerable <ResponseMessage> KarmaHandler(IncomingMessage message, IValidHandle matchedHandle) { var operatorMatches = _karmaPlugin.GetOperatorMatchesInMessage(message.FullText); var reasonMatches = _karmaPlugin.GetReasonMatchesInMessage(message.FullText); operatorMatches = operatorMatches.Where(x => reasonMatches.All(y => y.Index != x.Index)).ToList(); foreach (Match match in operatorMatches) { var changeRequest = _karmaPlugin.ParseKarmaChange(match.Value); yield return(HandleKarmaChange(message, changeRequest)); } foreach (Match match in reasonMatches) { var changeRequest = _karmaPlugin.ParseKarmaChangeWithReason(match.Value); yield return(HandleKarmaChange(message, changeRequest)); } }