Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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));
            }
        }