public void AmbiguousTwoWordThrows() { ParserCommand command1 = new ParserCommand("add"); ParserCommand command2 = new ParserCommand("add file"); // ReSharper disable once ObjectCreationAsStatement Should.Throw<ParserConfigurationException>(() => new CommandMapper(new[] { command1, command2 })); }
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 ParserCommand AddCommand(string commandText) { if (_commands.Any(x => x.Text == commandText)) { throw new ParserConfigurationException("Cannot add duplicate command '{0}'.", commandText); } var command = new ParserCommand(commandText); _commands.Add(command); return command; }
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); }
private void AddCommand(ParserCommand command) { AddCommand(command.Text, command); foreach (var alias in command.Aliases) { AddCommand(alias, command); } }
public void Add(Queue<string> words, ParserCommand command) { string word = words.Dequeue(); if (words.Count == 0) { if (_entries.ContainsKey(word)) { throw new ParserConfigurationException("Ambiguous command: {0}", word); } _commands.Add(word, command); } else { if (_commands.ContainsKey(word)) { throw new ParserConfigurationException("Ambiguous command: {0}", word); } Entry child; if (!_entries.TryGetValue(word, out child)) { child = new Entry(); _entries.Add(word, child); } child.Add(words, command); } }
private void AddCommand(string commandText, ParserCommand command) { Queue<string> queue = new Queue<string>(); foreach (var s in commandText.Split(' ')) { queue.Enqueue(s); } _root.Add(queue, command); }
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); }