public ParserContext(ParserConfiguration configuration, string text) { Configuration = configuration; Result = new ParseResult(); Lexer = new Lexer(text); Mapper = new CommandMapper(Configuration.Commands); }
public void InvalidFirstWordRejected() { ParserCommand command1 = new ParserCommand("add file"); ParserCommand command2 = new ParserCommand("add comment"); var mapper = new CommandMapper(new[] { command1, command2 }); mapper.Advance("remove"); mapper.State.ShouldBe(MapperState.Rejected); }
public void CanFindOneAndOnly() { ParserCommand command = new ParserCommand("add"); var mapper = new CommandMapper(new[] { command }); mapper.Advance("add"); mapper.State.ShouldBe(MapperState.Accepted); mapper.Command.ShouldBe(command); }
public void CanFindSecondOfTwo() { ParserCommand command1 = new ParserCommand("add"); ParserCommand command2 = new ParserCommand("remove"); var mapper = new CommandMapper(new[] { command1, command2 }); mapper.Advance("remove"); mapper.State.ShouldBe(MapperState.Accepted); mapper.Command.ShouldBe(command2); }
public void CanFindTwoWordCommand() { ParserCommand command1 = new ParserCommand("add file"); ParserCommand command2 = new ParserCommand("add comment"); var mapper = new CommandMapper(new[] { command1, command2 }); mapper.State.ShouldBe(MapperState.Initial); mapper.Advance("add"); mapper.State.ShouldBe(MapperState.Pending); mapper.Advance("comment"); mapper.State.ShouldBe(MapperState.Accepted); mapper.Command.ShouldBe(command2); }
public void InvalidSecondWordRejected() { ParserCommand command1 = new ParserCommand("add file"); ParserCommand command2 = new ParserCommand("add comment"); var mapper = new CommandMapper(new[] { command1, command2 }); mapper.Advance("add"); mapper.State.ShouldBe(MapperState.Pending); mapper.Advance("junk"); mapper.State.ShouldBe(MapperState.Rejected); }