public void LineAnd3()
        {
            ILineMatcher lineMatcher = Line.And(Line.Contains("One"), Line.Contains("Two"), Line.Contains("Three"));

            AssertDoesNotMatch(lineMatcher, null, "", "    ", "One", "Two", "Three", "One One", "Two Two", "One Two", "One Three", "Three One");
            AssertMatches(lineMatcher, "OneTwoThree", "ThreeTwoOne", "  One  Two  Three  ", "  Three  Two  One  ", "One  Two  Three", "Three  Two  One", "One One Two Three", "One Two Two Three", "One Two Three Three");
        }
        public void LineOr()
        {
            ILineMatcher lineMatcher = Line.Or(Line.StartsWith("AA"), Line.StartsWith("BB"));

            AssertDoesNotMatch(lineMatcher, null, "", "    ", "test", "TestAA", "TestBB");
            AssertMatches(lineMatcher, "AA", "BB", "AAC", "AATest", "BBTest");
        }
        public void LineIsNotEmpty()
        {
            ILineMatcher lineMatcher = Line.IsNotEmpty();

            AssertMatches(lineMatcher, "    ", "TESTING: ", "Testin", "testing");
            AssertDoesNotMatch(lineMatcher, null, string.Empty);
        }
 private void AssertDoesNotMatch(ILineMatcher matcher, IReader reader, params int[] args)
 {
     foreach (int i in args)
     {
         int lines;
         Assert.That(matcher.Matches(reader, i, out lines), Is.False, "{0} offset {1}: read {2} lines", reader, i, lines);
     }
 }
        public void LineContains()
        {
            ILineMatcher lineMatcher = Line.Contains("Testing");

            AssertDoesNotMatch(lineMatcher, null, "", "    ", "TESTING: ", "Testin", "testing");
            AssertMatches(lineMatcher, "Testing", "Testing  ", "Testing that this line matches", "TestingWithoutSpaces",
                          "That Testing in the middle matches", "At the End: Testing");
        }
        public void LineStartsWith()
        {
            ILineMatcher lineMatcher = Line.StartsWith("Testing");

            AssertDoesNotMatch(lineMatcher, null, "", "    ", "TESTING: ", "Testin", "   Testing", "testing",
                               "Ending with Testing");
            AssertMatches(lineMatcher, "Testing", "Testing  ", "Testing that this line matches", "TestingWithoutSpaces");
        }
 private void AssertMatches(ILineMatcher matcher, params string[] args)
 {
     foreach (string line in args)
     {
         Reader reader = Reader.CreateStringReader(line);
         int    lines;
         Assert.That(matcher.Matches(reader, 0, out lines), Is.True, "Line: '{0}'", line);
     }
 }
 private void AssertDoesNotMatch(ILineMatcher matcher, params string[] args)
 {
     foreach (string line in args)
     {
         Reader reader = Reader.CreateStringReader(line);
         int    lines;
         Assert.That(matcher.Matches(reader, 0, out lines), Is.False, line);
     }
 }
        public void DoesNotContain()
        {
            ILineMatcher lineMatcher = Line.DoesNotContain("Testing");

            // need to use "\n" as an empty string
            AssertMatches(lineMatcher, "\n", "    ", "TESTING: ", "Testin", "testing");
            AssertDoesNotMatch(lineMatcher, "Testing", "Testing  ", "Testing that this line matches", "TestingWithoutSpaces",
                               "That Testing in the middle matches", "At the End: Testing");
        }
Beispiel #10
0
 protected SingleLineParser(string name, ILineMatcher lineMatcher, ILineParser dataParser, ILineParser commentParser, IImpliedModelParser[] impliedModelParsers, ModelFactoryDelegate modelFactory)
 {
     this.name                = name;
     this.lineMatcher         = lineMatcher;
     this.dataParser          = dataParser;
     this.commentParser       = commentParser;
     this.impliedModelParsers = impliedModelParsers;
     this.modelFactory        = modelFactory;
 }
 protected SingleLineParser(string name, ILineMatcher lineMatcher, ILineParser dataParser, ILineParser commentParser, IImpliedModelParser[] impliedModelParsers, ModelFactoryDelegate modelFactory)
 {
     this.name = name;
     this.lineMatcher = lineMatcher;
     this.dataParser = dataParser;
     this.commentParser = commentParser;
     this.impliedModelParsers = impliedModelParsers;
     this.modelFactory = modelFactory;
 }
Beispiel #12
0
        /// <summary>
        /// Constructs a new instance of FileMatcherBase.
        /// </summary>
        /// <param name="matcher">
        /// The <see cref="ILineMatcher"/> to be used by implementers
        /// of this abstract class.
        /// </param>
        protected FileMatcherBase(ILineMatcher matcher)
        {
            if (matcher == null)
            {
                throw new ArgumentNullException("matcher");
            }

            Matcher = matcher;
        }
Beispiel #13
0
        public void TwoLines()
        {
            ILineMatcher multiple = Line.Multiple(Line.IsEqual("One"), Line.IsEqual("Two"));

            Reader reader = Reader.CreateStringReader("One\nTwo\nThree\nStop\nFour");
            int    linesRead;

            Assert.That(multiple.Matches(reader, 0, out linesRead), Is.True);
            Assert.That(linesRead, Is.EqualTo(2));
        }
Beispiel #14
0
        public void OptionalMissingFollowing()
        {
            ILineMatcher repeat = Line.Multiple(Line.Optional(Line.Contains("Stop")), Line.IsEqual("One"));

            Reader reader = Reader.CreateStringReader("One\nTwo");
            int    linesRead;

            Assert.That(repeat.Matches(reader, 0, out linesRead), Is.True);
            Assert.That(linesRead, Is.EqualTo(1));
        }
Beispiel #15
0
        public void NoStop()
        {
            ILineMatcher repeat = Line.Multiple(Line.Repeat(Line.Any()).Until(Line.Contains("Stop")));

            Reader reader = Reader.CreateStringReader("One\nTwo");
            int    linesRead;

            Assert.That(repeat.Matches(reader, 0, out linesRead), Is.True);
            Assert.That(linesRead, Is.EqualTo(2));
        }
Beispiel #16
0
        public void RepeatUntilWithLines()
        {
            ILineMatcher multiple = Line.Multiple(Line.Repeat(Line.Any()).Until(Line.Contains("Stop")), Line.Contains("Stop"));

            Reader reader = Reader.CreateStringReader("One\nTwo\nStop\nThree");
            int    linesRead;

            Assert.That(multiple.Matches(reader, 0, out linesRead), Is.True);
            Assert.That(linesRead, Is.EqualTo(3));
        }
Beispiel #17
0
        public void MatchingWithFollowingLine()
        {
            ILineMatcher followedBy = Line.FollowedBy(Line.Contains("Marker"), Line.Contains("Follow"));

            Reader reader = Reader.CreateStringReader("Marker\nFollow\nMore");
            int    linesRead;

            Assert.That(followedBy.Matches(reader, 0, out linesRead), Is.True);
            Assert.That(linesRead, Is.EqualTo(1));
        }
 protected ImpliedModelParser(string name, ILineMatcher lineMatcher, ILineParser modelParser, ILineParser impliedParser,
     ModelFactoryDelegate modelFactory, ModelFactoryDelegate impliedFactory)
 {
     this.name = name;
     this.lineMatcher = lineMatcher;
     this.modelParser = modelParser;
     this.impliedParser = impliedParser;
     this.modelFactory = modelFactory;
     this.impliedFactory = impliedFactory;
 }
Beispiel #19
0
 protected ImpliedModelParser(string name, ILineMatcher lineMatcher, ILineParser modelParser, ILineParser impliedParser,
                              ModelFactoryDelegate modelFactory, ModelFactoryDelegate impliedFactory)
 {
     this.name           = name;
     this.lineMatcher    = lineMatcher;
     this.modelParser    = modelParser;
     this.impliedParser  = impliedParser;
     this.modelFactory   = modelFactory;
     this.impliedFactory = impliedFactory;
 }
        public void LineOptional()
        {
            ILineMatcher lineMatcher = Line.Optional(Line.Contains("Testing"));

            // matches invalid lines
            AssertMatches(lineMatcher, null, "", "    ", "TESTING: ", "Testin", "testing");
            // matches valid lines
            AssertMatches(lineMatcher, "Testing", "Testing  ", "Testing that this line matches", "TestingWithoutSpaces",
                          "That Testing in the middle matches", "At the End: Testing");
        }
Beispiel #21
0
        public void RepeatLines()
        {
            ILineMatcher repeat = Line.Repeat(Line.Any()).Until(Line.Contains("Stop"));

            Reader reader = Reader.CreateStringReader("One\nTwo\nThree\nStop\nFour");
            int    linesRead;

            Assert.That(repeat.Matches(reader, 0, out linesRead), Is.True);
            Assert.That(linesRead, Is.EqualTo(3));
        }
Beispiel #22
0
        public void DoesNotMatchWithLateFollowing()
        {
            ILineMatcher followedBy = Line.FollowedBy(Line.Contains("Marker"), Line.Contains("Follow"));

            Reader reader = Reader.CreateStringReader("Marker\nMore\nFollow");
            int    linesRead;

            Assert.That(followedBy.Matches(reader, 0, out linesRead), Is.False);
            Assert.That(linesRead, Is.EqualTo(0));
        }
Beispiel #23
0
        public void ImmediateStop()
        {
            ILineMatcher repeat = Line.Repeat(Line.Any()).Until(Line.Contains("Stop"));

            Reader reader = Reader.CreateStringReader("Stop\nOne\nTwo");
            int    linesRead;

            Assert.That(repeat.Matches(reader, 0, out linesRead), Is.False);
            Assert.That(linesRead, Is.EqualTo(0));
        }
 public RepeatLineMatcher(ILineMatcher lineMatcher)
 {
     this.lineMatcher = lineMatcher;
     until = null;
 }
 public static ILineMatcher And(ILineMatcher one, ILineMatcher two, ILineMatcher three)
 {
     return new AndLineMatcher(new AndLineMatcher(one, two), three);
 }
Beispiel #26
0
 protected SingleLineParser(string name, ILineMatcher lineMatcher, ILineParser dataParser)
     : this(name, lineMatcher, dataParser, Comment.IgnoreAll(), null, StringModel.Factory)
 {
 }
 public static ILineMatcher FollowedBy(ILineMatcher line, ILineMatcher followedBy)
 {
     return new FollowedByMatcher(line, followedBy);
 }
 public static ILineMatcher Optional(ILineMatcher lineMatcher)
 {
     return new OptionalLineMatcher(lineMatcher);
 }
 public static IRepeatLineMatcher Repeat(ILineMatcher lineMatcher)
 {
     return new RepeatLineMatcher(lineMatcher);
 }
 private void AssertDoesNotMatch(ILineMatcher matcher, params string[] args)
 {
     foreach (string line in args)
     {
         Reader reader = Reader.CreateStringReader(line);
         int lines;
         Assert.That(matcher.Matches(reader, 0, out lines), Is.False, line);
     }
 }
 public AndLineMatcher(ILineMatcher primary, ILineMatcher secondary)
 {
     this.primary = primary;
     this.secondary = secondary;
 }
 public FollowedByMatcher(ILineMatcher line, ILineMatcher followedBy)
 {
     this.line = line;
     this.followedBy = followedBy;
 }
 protected BlockParser(ILineMatcher[] lineMatchers)
 {
     this.lineMatchers = lineMatchers;
 }
 protected SingleLineParser(string name, ILineMatcher lineMatcher, ILineParser dataParser, ILineParser commentParser)
     : this(name, lineMatcher, dataParser, commentParser, null, StringModel.Factory)
 {
 }
 protected SingleLineParser(string name, ILineMatcher lineMatcher, ILineParser dataParser)
     : this(name, lineMatcher, dataParser, Comment.IgnoreAll(), null, StringModel.Factory)
 {
 }
 public IRepeatLineMatcher Until(ILineMatcher untilMatcher)
 {
     until = untilMatcher;
     return this;
 }
 private void AssertDoesNotMatch(ILineMatcher matcher, IReader reader, params int[] args)
 {
     foreach (int i in args)
     {
         int lines;
         Assert.That(matcher.Matches(reader, i, out lines), Is.False, "{0} offset {1}: read {2} lines", reader, i, lines);
     }
 }
 /// <summary>
 /// Constructs a new instance of FileMatcher.
 /// </summary>
 /// <param name="matcher">
 /// The <see cref="ILineMatcher"/> to be used when matching individual lines.
 /// </param>
 public FileNotMatchingMatcher(ILineMatcher matcher)
     : base(matcher)
 {
 }
 public static ILineMatcher Or(ILineMatcher option1, ILineMatcher option2, ILineMatcher option3)
 {
     return new OrLineMatcher(new[] { option1, option2, option3});
 }
Beispiel #40
0
 public static ILineMatcher Optional(ILineMatcher lineMatcher)
 {
     return(new OptionalLineMatcher(lineMatcher));
 }
 public static ILineMatcher And(ILineMatcher primary, ILineMatcher alternate)
 {
     return new AndLineMatcher(primary, alternate);
 }
Beispiel #42
0
 public static ILineMatcher Or(ILineMatcher option1, ILineMatcher option2, ILineMatcher option3)
 {
     return(new OrLineMatcher(new[] { option1, option2, option3 }));
 }
 public static ILineMatcher And(ILineMatcher one, ILineMatcher two, ILineMatcher three, ILineMatcher four)
 {
     return new AndLineMatcher(new AndLineMatcher(one, two), new AndLineMatcher(three, four));
 }
Beispiel #44
0
 public static ILineMatcher And(ILineMatcher primary, ILineMatcher alternate)
 {
     return(new AndLineMatcher(primary, alternate));
 }
 public OrLineMatcher(ILineMatcher[] options)
 {
     this.options = options;
 }
Beispiel #46
0
 public static ILineMatcher And(ILineMatcher one, ILineMatcher two, ILineMatcher three)
 {
     return(new AndLineMatcher(new AndLineMatcher(one, two), three));
 }
Beispiel #47
0
 protected SingleLineParser(string name, ILineMatcher lineMatcher, ILineParser dataParser, ILineParser commentParser)
     : this(name, lineMatcher, dataParser, commentParser, null, StringModel.Factory)
 {
 }
Beispiel #48
0
 public static ILineMatcher And(ILineMatcher one, ILineMatcher two, ILineMatcher three, ILineMatcher four)
 {
     return(new AndLineMatcher(new AndLineMatcher(one, two), new AndLineMatcher(three, four)));
 }
 public OptionalLineMatcher(ILineMatcher lineMatcher)
 {
     this.lineMatcher = lineMatcher;
 }
Beispiel #50
0
 public static ILineMatcher FollowedBy(ILineMatcher line, ILineMatcher followedBy)
 {
     return(new FollowedByMatcher(line, followedBy));
 }
 public OptionalLineMatcher(ILineMatcher lineMatcher)
 {
     this.lineMatcher = lineMatcher;
 }
 private void AssertMatches(ILineMatcher matcher, params string[] args)
 {
     foreach (string line in args)
     {
         Reader reader = Reader.CreateStringReader(line);
         int lines;
         Assert.That(matcher.Matches(reader, 0, out lines), Is.True, "Line: '{0}'", line);
     }
 }
Beispiel #53
0
 public static IRepeatLineMatcher Repeat(ILineMatcher lineMatcher)
 {
     return(new RepeatLineMatcher(lineMatcher));
 }
Beispiel #54
0
 /// <summary>
 /// Constructs a new instance of FileMatcher.
 /// </summary>
 /// <param name="matcher">
 /// The <see cref="ILineMatcher"/> to be used when matching individual lines.
 /// </param>
 public FileMatcher(ILineMatcher matcher)
     : base(matcher)
 {
 }