public Parse ( string command, string &commandName ) : string>.IDictionary |
||
command | string | |
commandName | string | |
return | string>.IDictionary |
public void Parse_CommandNameOnlyWithLeadingSpace() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_simpleRoute); var commandName = ""; // Act var param = parser.Parse(" ls", out commandName); // Assert Assert.AreEqual(0, param.Count()); Assert.AreEqual("ls", commandName); }
public void Parse_OrderedCommandParser_AddsSwitchesToTheParamsCorrectly() { // Arrange var parser = new OrderedCommandParser(); var commandName = ""; parser.SetRoutes(_routing.GetRoutes()); // Act var param = parser.Parse("ls c:\\ProgramFiles *.csv /s /switch", out commandName); var route = _routing.FindRoute(commandName, param); // Assert Assert.IsTrue(param.ContainsKey("/s")); Assert.IsTrue(param.ContainsKey("/switch")); Assert.IsNotNull(route); Assert.AreEqual("ls", route.Name); }
public void Parse_WithSingleKeyValueParameter() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_singleParamRoute); var commandName = ""; // Act var param = parser.Parse(@"ls c:\", out commandName); // Assert Assert.AreEqual(1, param.Count()); Assert.AreEqual("ls", commandName); }
public void Parse_TwoParamsButNoRoutesAndThrowsAnException() { // Arrange var parser = new OrderedCommandParser(); var commandName = ""; // Act var param = parser.Parse("ls c:\\ProgramFiles \"*.csv", out commandName); }
public void Parse_TwoParamsSecondOneEscappedIncorrectlyAndThrowsAnException() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_twoParamRoute); var commandName = ""; // Act var param = parser.Parse("ls c:\\ProgramFiles \"*.csv", out commandName); }
public void Parse_TwoParamsSecondOneEscapped() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_twoParamRoute); var commandName = ""; // Act var param = parser.Parse("ls c:\\ProgramFiles \"*.csv\"", out commandName); // Assert Assert.AreEqual(2, param.Count()); Assert.AreEqual("path", param.Keys.First()); Assert.AreEqual("c:\\ProgramFiles", param.Values.First()); Assert.AreEqual("filter", param.Keys.Skip(1).Take(1).Single()); Assert.AreEqual(@"*.csv", param.Values.Skip(1).Take(1).Single()); }
public void Parse_ParamsGetExtraSpacesTrimmed() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_singleParamRoute); var commandName = ""; // Act var param = parser.Parse("ls c:\\ProgramFiles\\", out commandName); // Assert Assert.AreEqual(1, param.Count()); Assert.AreEqual("path", param.Keys.First()); Assert.AreEqual("c:\\ProgramFiles\\", param.Values.First()); }
public void Parse_SingleEscappedParam() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_singleParamRoute); var commandName = ""; // Act var param = parser.Parse("ls \"c:\\Program Files\"", out commandName); // Assert Assert.AreEqual(1, param.Count()); Assert.AreEqual("path", param.Keys.First()); Assert.AreEqual("c:\\Program Files", param.Values.First()); }
public void Parse_TwoParamAreSplitCorrectly() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_twoParamRoute); var commandName = ""; // Act var param = parser.Parse(@"ls c:\ *.csv", out commandName); // Assert Assert.AreEqual(2, param.Count()); Assert.AreEqual("path", param.Keys.First()); Assert.AreEqual(@"c:\", param.Values.First()); Assert.AreEqual("filter", param.Keys.Skip(1).Take(1).Single()); Assert.AreEqual(@"*.csv", param.Values.Skip(1).Take(1).Single()); }
public void Parse_WithTwoParamsOptionalNotSpecified() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_twoParamWithOptionalRoute); var commandName = ""; // Act var param = parser.Parse(@"ls c:\", out commandName); // Assert Assert.AreEqual(1, param.Count()); Assert.AreEqual("ls", commandName); }
public void Parse_WithTwoParameters() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_twoParamRoute); var commandName = ""; // Act var param = parser.Parse(@"ls c:\ *.csv", out commandName); // Assert Assert.AreEqual(2, param.Count()); Assert.AreEqual("ls", commandName); }
public void Parse_SingleParamIsSplitCorrectly() { // Arrange var parser = new OrderedCommandParser(); parser.SetRoutes(_singleParamRoute); var commandName = ""; // Act var param = parser.Parse(@"ls c:\", out commandName); // Assert Assert.AreEqual(1, param.Count()); Assert.AreEqual("path", param.Keys.First()); Assert.AreEqual(@"c:\", param.Values.First()); }
public void Parse_OrderedCommandParser_HandlesSwitchesAndRoutesTheCommandCorrectly() { // Arrange var parser = new OrderedCommandParser(); var commandName = ""; parser.SetRoutes(_routing.GetRoutes()); // Act var param = parser.Parse("ls c:\\ProgramFiles *.csv /s /switch", out commandName); var route = _routing.FindRoute(commandName, param); // Assert Assert.AreEqual("ls", commandName); Assert.AreEqual(4, param.Count); // two param and 2 switches Assert.IsNotNull(route); Assert.AreEqual("ls", route.Name); }