Ejemplo n.º 1
0
        public void ShouldReadAfterDiscardLogs()         // ex: used when a log file starts with comment
        {
            LogReader     reader;
            Log           log;
            StringMatcher stringMatcher;
            StringMatcher discardMatcher;

            stringMatcher = new StringMatcher();
            stringMatcher.Add("Line");

            discardMatcher = new StringMatcher();
            discardMatcher.Add("Line 0");
            discardMatcher.Add("Line 1");
            discardMatcher.Add("Line 2");
            discardMatcher.Add("Line 3");


            reader = new LogReader(new MockedLineReader(10), stringMatcher, discardMatcher);

            for (int t = 0; t < 6; t++)
            {
                log = reader.Read();
                Assert.AreEqual(t + 4, log.LineIndex);
                Assert.AreEqual($"Line {t+4}", log.ToSingleLine());
            }
            log = reader.Read();
            Assert.IsNull(log);
        }
Ejemplo n.º 2
0
 public InputProcessor()
 {
     fuzzyMatcher.Add("amount", 0);
     fuzzyMatcher.Add("interest", 1);
     fuzzyMatcher.Add("downpayment", 2);
     fuzzyMatcher.Add("term", 3);
 }
Ejemplo n.º 3
0
        public void ShouldDiscardLogs()
        {
            LogReader     reader;
            Log           log;
            StringMatcher stringMatcher;
            StringMatcher discardMatcher;

            stringMatcher = new StringMatcher();
            stringMatcher.Add("Line");

            discardMatcher = new StringMatcher();
            discardMatcher.Add("Line 1");
            discardMatcher.Add("Line 3");
            discardMatcher.Add("Line 5");
            discardMatcher.Add("Line 7");
            discardMatcher.Add("Line 9");


            reader = new LogReader(new MockedLineReader(10), stringMatcher, discardMatcher);

            for (int t = 0; t < 5; t++)
            {
                log = reader.Read();
                Assert.AreEqual(t * 2, log.LineIndex);
                Assert.AreEqual($"Line {t*2}", log.ToSingleLine());
            }
            log = reader.Read();
            Assert.IsNull(log);
        }
Ejemplo n.º 4
0
        public void ShouldDiscardLines()
        {
            StringMatcher discardMatcher;
            LineReader    reader;
            Line          line;

            discardMatcher = new StringMatcher();
            discardMatcher.Add("Line 1");
            discardMatcher.Add("Line 3");
            discardMatcher.Add("Line 5");
            discardMatcher.Add("Line 7");
            reader = new LineReader(new MockedStringReader(10), discardMatcher);

            line = reader.Read();
            Assert.AreEqual(0, line.Index);
            Assert.AreEqual($"Line 0", line.Value);
            line = reader.Read();
            Assert.AreEqual(2, line.Index);
            Assert.AreEqual($"Line 2", line.Value);
            line = reader.Read();
            Assert.AreEqual(4, line.Index);
            Assert.AreEqual($"Line 4", line.Value);
            line = reader.Read();
            Assert.AreEqual(6, line.Index);
            Assert.AreEqual($"Line 6", line.Value);
            line = reader.Read();
            Assert.AreEqual(8, line.Index);
            Assert.AreEqual($"Line 8", line.Value);
        }
        private void LoadDictionary()
        {
            List <String> linesInFile = GetLinesFromFile();

            _stringMatcher = new StringMatcher <String>();

            String englishTerm = "";

            foreach (String line in linesInFile)
            {
                if (line == String.Empty)
                {
                    continue;
                }
                else if (line.StartsWith("msgid"))
                {
                    englishTerm = GetParsedTerm(line);
                }
                else if (line.StartsWith("msgstr"))
                {
                    _stringMatcher.Add(englishTerm, GetParsedTerm(line));
                    DictionarySize++;
                }
            }
        }
Ejemplo n.º 6
0
        public void ShouldNotMatch()
        {
            StringMatcher matcher;
            Match         match;

            matcher = new StringMatcher();
            matcher.Add("bcd");
            Assert.AreEqual(false, matcher.Match("abc"));
            match = matcher.GetMatch("abc");
            Assert.AreEqual(null, match);
        }
        public void TestIgnoreLinebreaks()
        {
            StringMatcher <String> ignoreLinebreaksMatcher = new StringMatcher <String>(MatchingOption.RemoveSpacingAndLinebreaks);

            ignoreLinebreaksMatcher.Add("This has\nsome line\nbreaks.", "A string with linebreaks");

            SearchResultList <String> results = ignoreLinebreaksMatcher.Search("This has some line breaks.", 100.0f);

            Assert.AreEqual(1, results.Count);
            Assert.IsTrue(results.ContainsKeyword("This has\nsome line\nbreaks."));
        }
        public void TestIgnoreTabs()
        {
            StringMatcher <String> ignoreTabsMatcher = new StringMatcher <String>(MatchingOption.RemoveSpacingAndLinebreaks);

            ignoreTabsMatcher.Add("\t\tThis is some tabbed data", "A string with tabs");

            SearchResultList <String> results = ignoreTabsMatcher.Search("This is some tabbed \tdata", 100.0f);

            Assert.AreEqual(1, results.Count);
            Assert.IsTrue(results.ContainsKeyword("\t\tThis is some tabbed data"));
        }
Ejemplo n.º 9
0
        public void ShouldMatch()
        {
            StringMatcher matcher;
            Match         match;

            matcher = new StringMatcher();
            matcher.Add("abc");
            Assert.AreEqual(true, matcher.Match("abc"));
            match = matcher.GetMatch("abc");
            Assert.AreEqual(true, match.Success);
            Assert.AreEqual("abc", match.Value);
        }
Ejemplo n.º 10
0
        public IStringMatcher CreateStringMatcher(string NameSpace, IEnumerable <string> Patterns)
        {
            StringMatcher matcher;
            Regex         regex;

            matcher = new StringMatcher();
            foreach (string pattern in Patterns)
            {
                if (!Try(() => regexBuilder.Build(NameSpace, pattern, false)).OrAlert(out regex, $"Failed to build regex: {pattern}"))
                {
                    continue;
                }
                matcher.Add(regex);
            }
            return(matcher);
        }
Ejemplo n.º 11
0
        public void ShouldReadLogs()
        {
            LogReader     reader;
            Log           log;
            StringMatcher stringMatcher;

            stringMatcher = new StringMatcher();
            stringMatcher.Add("Line");

            reader = new LogReader(new MockedLineReader(10), stringMatcher, Utils.EmptyStringMatcher);

            for (int t = 0; t < 10; t++)
            {
                log = reader.Read();
                Assert.AreEqual(t, log.LineIndex);
                Assert.AreEqual($"Line {t}", log.ToSingleLine());
            }
            log = reader.Read();
            Assert.IsNull(log);
        }
        public static void SetupStringMatcher(TestContext context)
        {
            _stringMatcher.Add("0123456789", "10 digit long string");
            _stringMatcher.Add("012345678", "9 digit long string");
            _stringMatcher.Add("01234567", "8 digit long string");
            _stringMatcher.Add("0123456", "7 digit long string");
            _stringMatcher.Add("012345", "6 digit long string");
            _stringMatcher.Add("01234", "5 digit long string");
            _stringMatcher.Add("0123", "4 digit long string");
            _stringMatcher.Add("012", "3 digit long string");
            _stringMatcher.Add("01", "2 digit long string");
            _stringMatcher.Add("0", "1 digit long string");

            _stringMatcher.Add("Test", "String with uppercase char");
            _stringMatcher.Add("test", "String with all lowercase chars");

            _stringMatcher.Add("This is a test", "Multiple word string");

            _stringMatcher.Add("Cat", "Short string");
            _stringMatcher.Add("Bats", "Slightly longer short string");
        }