Beispiel #1
0
        public void FindAll_AXBY()
        {
            var matcher = new AhoCorasickSearch(new List <string>
            {
                "ax",
                "by"
            });

            matcher.FindAll(" if something then if goto J elsif");
        }
Beispiel #2
0
        public void FindAll_CommonPostfix_NoWordBreak_NoOverlap()
        {
            var matcher = new AhoCorasickSearch(new List <string>
            {
                "if",
                "elsif",
            }, false);

            var actual = matcher.FindAll(" elsif ").ToList();

            Assert.AreEqual(1, actual.Count, "Wrong number of matches");
            Assert.AreEqual("elsif", actual[0].Value, "Matched wrong keyword matched");
        }
Beispiel #3
0
        public void FindAll_CommonPostfix_NoWordBreak()
        {
            var matcher = new AhoCorasickSearch(new List <string>
            {
                "if",
                "elsif",
            }, false, true);
            TextReader rdr    = new StringReader("aaa");
            var        actual = matcher.FindAll(" elsif ").ToList();

            Assert.AreEqual(2, actual.Count, "Wrong number of matches");
            Assert.AreEqual("elsif", actual[0].Value, "Matched wrong keyword matched (1)");
            Assert.AreEqual("if", actual[1].Value, "Matched wrong keyword matched (2)");
        }
Beispiel #4
0
        public void FindAll_CommonPostfix()
        {
            var matcher = new AhoCorasickSearch(new List <string>
            {
                "if",
                "elsif",
            });

            var actual = matcher.FindAll(" elsif ").ToList();

            Assert.AreEqual(1, actual.Count, "Wrong number of matches");
            Assert.AreEqual(1, actual[0].Position, "Matched wrong position");
            Assert.AreEqual(5, actual[0].Length, "Matched wrong length");
            Assert.AreEqual("elsif", actual[0].Value, "Matched wrong keyword");
        }
Beispiel #5
0
        public void FindAll_CommonPrefix_NoWordBreakB_NoOverlap()
        {
            var matcher = new AhoCorasickSearch(new List <string>
            {
                "if",
                "ifa",
                "ifb"
            }, false);

            var actual = matcher.FindAll("xifax").ToList();

            Assert.AreEqual(1, actual.Count, "Wrong number of matches");
            Assert.AreEqual(1, actual[0].Position, "Matched wrong position");
            Assert.AreEqual(3, actual[0].Length, "Matched wrong length");
            Assert.AreEqual("ifa", actual[0].Value, "Matched wrong keyword");
        }
Beispiel #6
0
        public void FindAll_MultipleMatches()
        {
            var matcher = new AhoCorasickSearch(new List <string>
            {
                "if",
                "ifa",
                "ifb"
            });

            var actual = matcher.FindAll("Matches 'ifa', 'ifb' and 'if' in a longer text, Keywords: if, ifa, ifb").ToList();

            Assert.AreEqual(6, actual.Count, "Wrong number of matches");

            Assert.AreEqual("ifa", actual[0].Value, "Matched wrong keyword");
            Assert.AreEqual("ifb", actual[1].Value, "Matched wrong keyword");
            Assert.AreEqual("if", actual[2].Value, "Matched wrong keyword");
            Assert.AreEqual("if", actual[3].Value, "Matched wrong keyword");
            Assert.AreEqual("ifa", actual[4].Value, "Matched wrong keyword");
            Assert.AreEqual("ifb", actual[5].Value, "Matched wrong keyword");
        }