예제 #1
0
 public ParserContext(ParserConfiguration configuration, string text)
 {
     Configuration = configuration;
     Result = new ParseResult();
     Lexer = new Lexer(text);
     Mapper = new CommandMapper(Configuration.Commands);
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }