public void Build_AfterAddParameterCalled_ReturnsCommandInputWithNumberedParameter() { // arrange var sut = new CommandInput.Builder(3, "command"); sut.AddParameter(new LiteralCommandParameter("value1")); sut.AddParameter(new LiteralCommandParameter("value2")); // act var commandInput = sut.Build(); // assert Assert.Equal("value1", (commandInput.Parameters[0] as LiteralCommandParameter).Value); Assert.Equal("value2", (commandInput.Parameters[1] as LiteralCommandParameter).Value); }
private CommandInput ParseCommandInput() { var parsedBlock = ParseBlock(); if (parsedBlock.Block == null) { return(null); } if (parsedBlock.Block.GetType() != typeof(LiteralCommandParameter)) { throw new ParseException(parsedBlock.LocationStart, "Command name must be a literal."); } var commandInputBuilder = new CommandInput.Builder(parsedBlock.LocationStart.LineNumber, (parsedBlock.Block as LiteralCommandParameter).Value); while (!parsedBlock.IsEndOfLine) { parsedBlock = ParseBlock(); if (parsedBlock.Block != null) { commandInputBuilder.AddParameter(parsedBlock.Block); } } return(commandInputBuilder.Build()); }
public void Parse_MultipleBracketedParameters_ParametersParsedProperly() { // arrange var sut = new Parser(); var builder = new CommandInput.Builder(1, "command"); builder.AddParameter(new LiteralCommandParameter("pa ram")); builder.AddParameter(new LiteralCommandParameter("pa ram")); var expectedCommand = builder.Build(); // act var result = sut.Parse("command (pa ram) (pa ram)"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
public void Parse_EscapedCommentSymbol_CommentSymbolIncludedInParameter() { // arrange var sut = new Parser(); var builder = new CommandInput.Builder(1, "command"); builder.AddParameter(new LiteralCommandParameter("#")); builder.AddParameter(new LiteralCommandParameter("param")); var expectedCommand = builder.Build(); // act var result = sut.Parse(@"command \# param"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
public void Parse_NamedParameters_ParameterParsed(string input) { // arrange var sut = new Parser(); var builder = new CommandInput.Builder(1, "command"); builder.AddParameter(new ParameterNameCommandParameter("name")); builder.AddParameter(new LiteralCommandParameter("value")); var expectedCommand = builder.Build(); // act var result = sut.Parse(input); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
private CommandInput CreateCommandInput(string commandName, params CommandParameter[] parameters) { var builder = new CommandInput.Builder(1, commandName); foreach (var parameter in parameters) { builder.AddParameter(parameter); } return(builder.Build()); }
public void AddParameter_ParameterIsNull_ThrowsException() { // arrange var sut = new CommandInput.Builder(1, "command"); Action sutAction = () => sut.AddParameter(null); // act, assert var ex = Assert.Throws <ArgumentNullException>(sutAction); Assert.Equal("value", ex.ParamName); }
public void Build_EmptyOrWhiteSpaceParameter_ReturnsCommandInputWithParameter(string value) { // arrange var sut = new CommandInput.Builder(3, "command"); sut.AddParameter(new LiteralCommandParameter(value)); // act var commandInput = sut.Build(); // assert Assert.Equal(value, (commandInput.Parameters[0] as LiteralCommandParameter).Value); }
public void Parse_TwoCommandsTwoParameters_ParsedCommandsWithParameters(string input) { // arrange var sut = new Parser(); var builder1 = new CommandInput.Builder(1, "command"); builder1.AddParameter(new LiteralCommandParameter("param1")); builder1.AddParameter(new LiteralCommandParameter("param2")); var expectedCommand1 = builder1.Build(); var builder2 = new CommandInput.Builder(2, "command"); builder2.AddParameter(new LiteralCommandParameter("param1")); builder2.AddParameter(new LiteralCommandParameter("param2")); var expectedCommand2 = builder2.Build(); // act var result = sut.Parse(input); // assert Assert.Equal(new[] { expectedCommand1, expectedCommand2 }, result, new CommandInputEqualityComparer()); }
public void Parse_NestedBracketsInParameters_ParameterIncludesBrackets() { // arrange var sut = new Parser(); var builder = new CommandInput.Builder(1, "command"); builder.AddParameter(new LiteralCommandParameter("\nic (pa ram)\nic (pa ram)")); var expectedCommand = builder.Build(); // act var result = sut.Parse("command (\nic \\(pa ram\\)\nic \\(pa ram\\))"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
public void Parse_NewlineInsideBracketedParameter_ParameterIncludesNewline() { // arrange var sut = new Parser(); var builder = new CommandInput.Builder(1, "command"); builder.AddParameter(new LiteralCommandParameter("param\nparam")); var expectedCommand = builder.Build(); // act var result = sut.Parse("command (param\nparam)"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
public void Parse_ParameterIncludesSlash_ParameterParsed() { // arrange var sut = new Parser(); var builder = new CommandInput.Builder(1, "command"); builder.AddParameter(new LiteralCommandParameter(@"\")); var expectedCommand = builder.Build(); // act var result = sut.Parse(@"command \\"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
public void Parse_ParameterIsOnlyNewlines_NewlinesIncludedInParameter() { // arrange var sut = new Parser(); var builder = new CommandInput.Builder(1, "command"); builder.AddParameter(new LiteralCommandParameter("\n\n")); var expectedCommand = builder.Build(); // act var result = sut.Parse("command (\n\n)"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
public void Parse_InputContainsParameterNameSymbolInsideBlock_ParsesAsLiteral() { // arrange var builder = new CommandInput.Builder(1, "cmd"); builder.AddParameter(new LiteralCommandParameter("p -ar")); var expectedCommand = builder.Build(); var sut = new Parser(); // act var result = sut.Parse("cmd (p -ar)"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
public void Parse_InputContainsParameterName_ParsesParameterName() { // arrange var builder = new CommandInput.Builder(1, "cmd"); builder.AddParameter(new ParameterNameCommandParameter("par")); var expectedCommand = builder.Build(); var sut = new Parser(); // act var result = sut.Parse("cmd -par"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }
public void Parse_InputContainsEscapedVariableSymbol_ParseSymbolAsLiteral() { // arrange var builder = new CommandInput.Builder(1, "cmd"); builder.AddParameter(new LiteralCommandParameter("$var$")); var expectedCommand = builder.Build(); var sut = new Parser(); // act var result = sut.Parse(@"cmd \$var\$"); // assert Assert.Equal(expectedCommand, result[0], new CommandInputEqualityComparer()); }