示例#1
0
        public void ShouldNotBuildSituationSegmentAndThrowException()
        {
            IPredicate               predicate;
            SituationSegment         nextSegment;
            ISituationSegmentFactory factory;

            predicate = Parse.Character('a');

            nextSegment = new SituationSegment();
            nextSegment.InputTransitions.Add(new ReductionTransition());

            factory = new SituationSegmentFactory();
            Assert.ThrowsException <ArgumentNullException>(() => factory.BuildSituationSegment(predicate, null));
            Assert.ThrowsException <ArgumentNullException>(() => factory.BuildSituationSegment(null, nextSegment));
        }
示例#2
0
        public void ShouldNotBuildSituationSegmentUsingInvalidZeroOrMoreTimes()
        {
            IPredicate               predicate;
            SituationSegment         nextSegment;
            ISituationSegmentFactory factory;

            predicate = new ZeroOrMoreTimes();

            nextSegment = new SituationSegment();
            nextSegment.InputTransitions.Add(new ReductionTransition());

            factory = new SituationSegmentFactory();
            Assert.ThrowsException <InvalidOperationException>(() => factory.BuildSituationSegment(predicate, nextSegment));
        }
示例#3
0
        public void ShouldBuildSituationSegmentUsingCharacterPredicate()
        {
            IPredicate               predicate;
            SituationSegment         nextSegment;
            ISituationSegmentFactory factory;
            ISituationSegment        segment;

            predicate = Parse.Character('a');

            nextSegment = new SituationSegment();
            nextSegment.InputTransitions.Add(new ReductionTransition());

            factory = new SituationSegmentFactory();
            segment = factory.BuildSituationSegment(predicate, nextSegment);

            Assert.IsTrue(ParseSegment(segment, typeof(Character)));
        }
示例#4
0
        public void ShouldBuildSituationSegmentUsingComplexPredicate()
        {
            IPredicate               predicate;
            SituationSegment         nextSegment;
            ISituationSegmentFactory factory;
            ISituationSegment        segment;

            #region or inside a sequence
            predicate = Parse.AnyCharacter().Then(Parse.Character('a').OrCharacter('b')).ThenAnyCharacter();

            nextSegment = new SituationSegment();
            nextSegment.InputTransitions.Add(new ReductionTransition());

            factory = new SituationSegmentFactory();
            segment = factory.BuildSituationSegment(predicate, nextSegment);

            Assert.IsTrue(ParseSegment(segment, typeof(AnyCharacter), typeof(Character), typeof(AnyCharacter)));
            #endregion

            #region optional sequence in sequence
            predicate = Parse.AnyCharacter().Then(Parse.Character('a').ThenCharacter('b').Perhaps()).ThenAnyCharacter();

            nextSegment = new SituationSegment();
            nextSegment.InputTransitions.Add(new ReductionTransition());

            factory = new SituationSegmentFactory();
            segment = factory.BuildSituationSegment(predicate, nextSegment);

            Assert.IsTrue(ParseSegment(segment, typeof(AnyCharacter), typeof(Character), typeof(Character), typeof(AnyCharacter)));
            Assert.IsTrue(ParseSegment(segment, typeof(AnyCharacter), typeof(AnyCharacter)));
            #endregion

            #region one or more inside a sequence
            predicate = Parse.AnyCharacter().Then(Parse.Character('b').OneOrMoreTimes()).ThenAnyCharacter();

            nextSegment = new SituationSegment();
            nextSegment.InputTransitions.Add(new ReductionTransition());

            factory = new SituationSegmentFactory();
            segment = factory.BuildSituationSegment(predicate, nextSegment);

            Assert.IsTrue(ParseSegment(segment, typeof(AnyCharacter), typeof(Character), typeof(AnyCharacter)));
            Assert.IsTrue(ParseSegment(segment, typeof(AnyCharacter), typeof(Character), typeof(Character), typeof(Character), typeof(AnyCharacter)));
            #endregion
        }
示例#5
0
        public void ShouldBuildSituationSegmentUsingOneOrMoreTimes()
        {
            IPredicate               predicate;
            SituationSegment         nextSegment;
            ISituationSegmentFactory factory;
            ISituationSegment        segment;

            predicate = Parse.Character('a').OneOrMoreTimes();

            nextSegment = new SituationSegment();
            nextSegment.InputTransitions.Add(new ReductionTransition());

            factory = new SituationSegmentFactory();
            segment = factory.BuildSituationSegment(predicate, nextSegment);

            Assert.ThrowsException <Exception>(() => ParseSegment(segment));
            Assert.IsTrue(ParseSegment(segment, typeof(Character), typeof(Character), typeof(Character)));
        }