public void MultiCharTokenWithNextTest()
        {
            ParsingContextTestImpl context   = new ParsingContextTestImpl();
            ParsingStateTestImpl   nextState = new ParsingStateTestImpl(ParsingResult.Match);
            MatchTokenParsingState target    = new MatchTokenParsingState(",;:!");

            target.AddNextState(nextState);

            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'a'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'c'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ';'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '!'), ParsingResult.Match);
            Assert.AreEqual <IParsingState>(nextState, context.CurrentState);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'y'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ';'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'z'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ';'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '!'), ParsingResult.Match);
            Assert.AreEqual <IParsingState>(nextState, context.CurrentState);
        }
        public void MultiCharTokenWithNextAndErrorTest()
        {
            ParsingContextTestImpl context    = new ParsingContextTestImpl();
            ParsingStateTestImpl   nextState  = new ParsingStateTestImpl(ParsingResult.Match);
            ParsingStateTestImpl   errorState = new ParsingStateTestImpl(ParsingResult.Match);

            MatchTokenParsingState target = new MatchTokenParsingState(":=>");

            target.AddNextState(nextState);
            target.SetErrorState(errorState);

            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'f'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 't'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
            Assert.AreEqual <IParsingState>(errorState, context.CurrentState);
            Assert.AreEqual <string>(":", context.CurrentText);
            context.ResetText();
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '='), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '>'), ParsingResult.Match);
            Assert.AreEqual <IParsingState>(nextState, context.CurrentState);
            Assert.AreEqual <string>(string.Empty, context.CurrentText);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'y'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'm'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '='), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '>'), ParsingResult.Match);
            Assert.AreEqual <IParsingState>(nextState, context.CurrentState);
            Assert.AreEqual <string>(string.Empty, context.CurrentText);
        }
        private static void TestLinkedStates(ParsingResult [] returnResults, int transitionIndex)
        {
            ParsingState  target        = new ParsingState();
            ParsingResult finalResult   = ParsingResult.Match;
            IParsingState expectedState = target;

            for (int i = 0; i < returnResults.Length; i++)
            {
                ParsingResult        result    = returnResults[i];
                ParsingStateTestImpl nextState = new ParsingStateTestImpl(result);
                target.AddNextState(nextState);
                if (i == transitionIndex)
                {
                    finalResult = result;
                    if (finalResult != ParsingResult.Miss)
                    {
                        expectedState = nextState;
                    }
                    else
                    {
                        expectedState = target;
                    }
                }
            }

            ParsingContextTestImpl context = new ParsingContextTestImpl();

            context.CurrentState = target;
            char randomChar = (char)(new Random().Next(char.MinValue, char.MaxValue));

            Assert.AreEqual(target.ProcessCharacter(context, randomChar), finalResult);
            Assert.AreEqual <IParsingState>(expectedState, context.CurrentState);
        }
        public void MultiCharTokenWithEscapingTest()
        {
            ParsingContextTestImpl        context = new ParsingContextTestImpl();
            MatchEscapedTokenParsingState target  = new MatchEscapedTokenParsingState(":\":");

            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'a'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'c'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'd'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Done);
        }
        public void SingleCharTokenTest()
        {
            ParsingContextTestImpl context = new ParsingContextTestImpl();
            MatchTokenParsingState target  = new MatchTokenParsingState(",");

            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'a'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'c'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Done);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
            Assert.AreEqual <ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Done);
        }
        public void ProcessRegularCharacterTest()
        {
            ParsingContextTestImpl context = new ParsingContextTestImpl();
            ParsingState           target  = new ParsingState();
            FileReaderTestImpl     reader  = new FileReaderTestImpl(50);

            System.Text.StringBuilder localText = new System.Text.StringBuilder();
            while (!reader.IsEOF)
            {
                char nextChar = reader.GetNextChar();
                localText.Append(nextChar);
                Assert.AreEqual(target.ProcessCharacter(context, nextChar), ParsingResult.Match);
                Assert.AreEqual <string>(localText.ToString(), context.CurrentText);
            }
        }
 public void SingleCharTokenTest()
 {
     ParsingContextTestImpl context = new ParsingContextTestImpl();
     MatchTokenParsingState target = new MatchTokenParsingState(",");
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'a'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'c'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Done);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Done);
 }
        public void MultiCharTokenWithNextAndErrorTest()
        {
            ParsingContextTestImpl context = new ParsingContextTestImpl();
            ParsingStateTestImpl nextState = new ParsingStateTestImpl(ParsingResult.Match);
            ParsingStateTestImpl errorState = new ParsingStateTestImpl(ParsingResult.Match);

            MatchTokenParsingState target = new MatchTokenParsingState(":=>");
            target.AddNextState(nextState);
            target.SetErrorState(errorState);

            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'f'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 't'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
            Assert.AreEqual<IParsingState>(errorState, context.CurrentState);
            Assert.AreEqual<string>(":", context.CurrentText);
            context.ResetText();
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '='), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '>'), ParsingResult.Match);
            Assert.AreEqual<IParsingState>(nextState, context.CurrentState);
            Assert.AreEqual<string>(string.Empty, context.CurrentText);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'y'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'm'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '='), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '>'), ParsingResult.Match);
            Assert.AreEqual<IParsingState>(nextState, context.CurrentState);
            Assert.AreEqual<string>(string.Empty, context.CurrentText);
        }
        public void MultiCharTokenWithNextTest()
        {
            ParsingContextTestImpl context = new ParsingContextTestImpl();
            ParsingStateTestImpl nextState = new ParsingStateTestImpl(ParsingResult.Match);
            MatchTokenParsingState target = new MatchTokenParsingState(",;:!");
            target.AddNextState(nextState);

            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'a'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'c'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ';'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '!'), ParsingResult.Match);
            Assert.AreEqual<IParsingState>(nextState, context.CurrentState);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'y'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ';'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'z'), ParsingResult.Miss);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ';'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
            Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '!'), ParsingResult.Match);
            Assert.AreEqual<IParsingState>(nextState, context.CurrentState);
        }
 public void MultiCharTokenWithEscapingTest()
 {
     ParsingContextTestImpl context = new ParsingContextTestImpl();
     MatchEscapedTokenParsingState target = new MatchEscapedTokenParsingState(":\":");
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'a'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'c'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'd'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Done);
 }
Exemplo n.º 11
0
 public void ProcessRegularCharacterTest()
 {
     ParsingContextTestImpl context = new ParsingContextTestImpl();
     ParsingState target = new ParsingState();
     FileReaderTestImpl reader = new FileReaderTestImpl(50);
     System.Text.StringBuilder localText = new System.Text.StringBuilder();
     while (!reader.IsEOF)
     {
         char nextChar = reader.GetNextChar();
         localText.Append(nextChar);
         Assert.AreEqual(target.ProcessCharacter(context, nextChar), ParsingResult.Match);
         Assert.AreEqual<string>(localText.ToString(), context.CurrentText);
     }
 }
Exemplo n.º 12
0
        private static void TestLinkedStates(ParsingResult [] returnResults, int transitionIndex)
        {
            ParsingState target = new ParsingState();
            ParsingResult finalResult = ParsingResult.Match;
            IParsingState expectedState = target;

            for (int i=0; i< returnResults.Length; i++)
            {
                ParsingResult result = returnResults[i];
                ParsingStateTestImpl nextState = new ParsingStateTestImpl(result);
                target.AddNextState(nextState);
                if (i == transitionIndex)
                {
                    finalResult = result;
                    if (finalResult != ParsingResult.Miss)
                    {
                        expectedState = nextState;
                    }
                    else
                    {
                        expectedState = target;
                    }
                }
            }

            ParsingContextTestImpl context = new ParsingContextTestImpl();
            context.CurrentState = target;
            char randomChar = (char)(new Random().Next(char.MinValue, char.MaxValue));
            Assert.AreEqual(target.ProcessCharacter(context, randomChar), finalResult);
            Assert.AreEqual<IParsingState>(expectedState, context.CurrentState);
        }