Exemple #1
0
        public void Matches_GivenTextWithNoMatches_ReturnsEmptyList(MatcherFactory.MatchAlgorithm algorithm,
                                                                    List <string> patterns, String testString)
        {
            var matcher = factory.Create(patterns, algorithm);

            Assert.IsEmpty(matcher.Matches(new StringReader(testString)));
        }
Exemple #2
0
        public void IsMatch_GivenTextWithNoMatches_ReturnsFalse(MatcherFactory.MatchAlgorithm algorithm,
                                                                List <string> patterns, String testString)
        {
            var matcher = factory.Create(patterns, algorithm);

            Assert.IsFalse(matcher.IsMatch(new StringReader(testString)));
        }
Exemple #3
0
        public void Matches_GivenTextWithMatches_ReturnsListWithMatches(MatcherFactory.MatchAlgorithm algorithm,
                                                                        List <string> patterns, String testString,
                                                                        List <Match> expectedMatches)
        {
            var matcher = factory.Create(patterns, algorithm);

            Assert.IsTrue(Enumerable.SequenceEqual(matcher.Matches(new StringReader(testString)), expectedMatches));
        }
Exemple #4
0
        public void Match_GivenTextWithMatches_ReturnsMatch(MatcherFactory.MatchAlgorithm algorithm,
                                                            List <string> patterns, String testString,
                                                            Match expectedMatch)
        {
            var matcher = factory.Create(patterns, algorithm);

            Assert.AreEqual(matcher.Match(new StringReader(testString)), expectedMatch);
        }
Exemple #5
0
        public void IsMatch_GivenMultipleLinesString_AndTextWithAMatch_ReturnsTrue(MatcherFactory.MatchAlgorithm algorithm)
        {
            var matcher = factory.Create(new List <string> {
                "p1"
            }, algorithm);
            var text = "12\r\np13456\r\n7p189p10";

            Assert.IsTrue(matcher.IsMatch(new StringReader(text)));
        }
Exemple #6
0
        public void IsMatch_GivenMultipleLinesStream_AndTextWithAMatch_ReturnsTrue(MatcherFactory.MatchAlgorithm algorithm)
        {
            var matcher = factory.Create(new List <string> {
                "p1"
            }, algorithm);

            using (var stream = new MemoryStream())
            {
                var writer = new StreamWriter(stream);
                writer.WriteLine("12");
                writer.WriteLine("p13456");
                writer.WriteLine("7p189p10");
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                Assert.IsTrue(matcher.IsMatch(new StreamReader(stream)));
            }
        }
Exemple #7
0
        public void Matches_GivenMultipleLinesSring_AndTextWithAMatch_ReturnsListWithTheMatch_CountingTheNewline(MatcherFactory.MatchAlgorithm algorithm)
        {
            var matcher = factory.Create(new List <string> {
                "p1"
            }, algorithm);
            var text            = "12\r\np13456\r\n7p189p10";
            var expectedMatches = new List <Match> {
                new Match(4, "p1"), new Match(13, "p1"), new Match(17, "p1")
            };

            Assert.IsTrue(Enumerable.SequenceEqual(matcher.Matches(new StringReader(text)), expectedMatches));
        }
Exemple #8
0
        public void Match_GivenMultipleLinesString_AndTextWithAMatch_ReturnsTheMatch_CountingTheNewline(MatcherFactory.MatchAlgorithm algorithm)
        {
            var matcher = factory.Create(new List <string> {
                "p1"
            }, algorithm);
            var text = "12\r\np13456\r\n7p189p10";

            Assert.AreEqual(matcher.Match(new StringReader(text)), new Match(4, "p1"));
        }
Exemple #9
0
        public void Matches_GivenMultipleLinesStream_AndTextWithAMatch_ReturnsListWithTheMatch_CountingTheNewline(MatcherFactory.MatchAlgorithm algorithm)
        {
            var matcher = factory.Create(new List <string> {
                "p1"
            }, algorithm);

            using (var stream = new MemoryStream())
            {
                var writer = new StreamWriter(stream);
                writer.WriteLine("12");
                writer.WriteLine("p13456");
                writer.WriteLine("7p189p10");
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                var expectedMatches = new List <Match> {
                    new Match(4, "p1"), new Match(13, "p1"), new Match(17, "p1")
                };
                Assert.IsTrue(Enumerable.SequenceEqual(matcher.Matches(new StreamReader(stream)), expectedMatches));
            }
        }