public void NullParsingContextTest() { ParsingState target = new ParsingState(); target.ProcessCharacter(null, 'a'); }
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); } }
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); }