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