Beispiel #1
0
 public void ProcessMissingRequiredNamedVariable()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedTrueFalse, true, "A"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedVariable, true, "B"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true));
         cl.ProcessCommandLine(GoodTests.GetArgs($"UnNamed -B \"This is a part of -B\""));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"The required boolean switch -A is not defined", e.Message);
     }
 }
Beispiel #2
0
 public void ProcessMissingValueUnNamed()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedVariable, true, "A"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedVariable, true, "B"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true));
         cl.ProcessCommandLine(GoodTests.GetArgs($"-A Test -B 123"));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"There must be 1 parameters without switches", e.Message);
     }
 }
Beispiel #3
0
 public void ProcessToFewRequiredUnnamed()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true));
         cl.ProcessCommandLine(GoodTests.GetArgs($"Black Box"));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"There must be 3 parameters without switches", e.Message);
     }
 }
Beispiel #4
0
 public void ProcessMissingRequiredSwitches()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedTrueFalse, true, "A"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedVariable, true, "B"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true));
         cl.ProcessCommandLine(GoodTests.GetArgs($"-A \"This looks like part of /A but it isn't\""));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"The required value switch -B is not defined", e.Message);
     }
 }
Beispiel #5
0
 public void ProcessToManyRequiredUnnamed()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, true));
         cl.ProcessCommandLine(GoodTests.GetArgs($"3 2 1 Testing"));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"The item \"Testing\" exceeds the number of allowed values", e.Message);
     }
 }
Beispiel #6
0
 public void ProcessSwitchNotDefined()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedTrueFalse, false, "A"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedVariable, false, "B"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, false));
         cl.ProcessCommandLine(GoodTests.GetArgs($"/X"));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"The switch /X is not a valid switch", e.Message);
     }
 }
Beispiel #7
0
 public void ProcessNoValue()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedTrueFalse, false, "A"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedVariable, false, "B"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, false));
         cl.ProcessCommandLine(GoodTests.GetArgs($"/b"));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"This switch requires a value to be specified. e.g. /b 'somevalue'", e.Message);
     }
 }
Beispiel #8
0
 public void ProcessDuplicateSlashSwitch()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedTrueFalse, false, "A"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedVariable, false, "B"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, false));
         cl.ProcessCommandLine(GoodTests.GetArgs($"/A -a"));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"The -a switch has already been declared", e.Message);
     }
 }
Beispiel #9
0
 public void ProcessCommandLineSlashByItself()
 {
     try
     {
         CommandLineProcessor cl = CommandLineProcessor.Create(
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedTrueFalse, false, "A"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.NamedVariable, false, "B"),
             new ArgumentDescription(ArgumentDescription.ParameterTypeEnum.UnNamed, false));
         cl.ProcessCommandLine(GoodTests.GetArgs($"/"));
     }
     catch (UserInputException e)
     {
         Assert.AreEqual($"Cannot specify '/' by itself. Please use a switch name", e.Message);
     }
 }