public void delegateFact() { int portNumber = -1; CommandLineIntOption portOption = new CommandLineIntOption("port", "p"); portOption.Delegate = arg => portNumber = arg.Value; parser.AddOption(portOption); parser.Parse(new string[] {"-p8080"}); Assert.Equal(8080, portNumber); }
public void floatParameterThrowsException() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); parser.AddOption(port); Assert.Throws<ParsingException>( delegate { parser.Parse(new string[] { "--port", "4.0" }); }); }
public void lesserThanMinValueThrowsException() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); port.MaxValue = 1; port.MinValue = -1; parser.AddOption(port); Assert.Throws<ParsingException>( delegate { parser.Parse(new string[] { "--port", "-37" }); }); }
static void Example3(string[] args) { CommandLineParser parser = new CommandLineParser(); int intValue = 0; CommandLineIntOption intOption = new CommandLineIntOption("number"); intOption.MinValue = 100; intOption.MaxValue = 200; intOption.ParameterType = ParameterType.Optional; intOption.Delegate = x => intValue = x.Value; parser.AddOption(intOption); parser.Parse(args); Console.WriteLine("Value: " + intValue); }
static void Main(string[] args) { TestGnuTime(); TestValueType(); TestRequiredAndOptionalParameters(); TestExceptions(); TestOptionalParameters(); TestTerminator(); TestParsingException(); TestConfigExceptions(); TestRequiredOption(); //args = new string[] { "--listen", "--port", "80", "--hello=world" }; args = new string[] { "-p", "80", "-l", "naky", "navic" }; //args = new string[] { "-lp80" }; //args = new string[] { "--port=100000" }; //args = new string[] { "--hello=world" }; CommandLineParser parser = new CommandLineParser(); CommandLineIntOption p = new CommandLineIntOption("port", "p"); p.MaxValue = 65535; p.Delegate = x => Console.WriteLine("Já jsem delegát: " + x.Value); parser.AddOption(p); CommandLineBoolOption l = new CommandLineBoolOption(name: "listen", shortName: "l"); parser.AddOption(l); CommandLineStringOption s = new CommandLineStringOption("hello"); s.AllowedValues.AddRange(new string[] { "abc", "def", "ghi" }); parser.AddOption(s); List<string> extraParameters; //try { // run the parser extraParameters = parser.Parse(args); } /*catch (ParsingException e) { Console.WriteLine(e.Message); return; }*/ /*catch (OptionNotFoundException e) { Console.WriteLine(e.Message); return; }*/ Console.WriteLine("p.Value: " + p.Value); Console.WriteLine("l.Present: " + l.Present); Console.WriteLine("s.Value: " + s.Value); Console.WriteLine("extraParameters: " + string.Join(",", extraParameters)); }
static void TestValueType() { CommandLineParser parser = new CommandLineParser(); CommandLineIntOption intOption = new CommandLineIntOption("int", "i"); parser.AddOption(intOption); var otherParams = parser.Parse(new string[] { "-i", "10" }); TestAssert(intOption.Value == 10); TestAssert(intOption.Value.GetType() == typeof(int)); }
public void maxValueBorderFact() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); port.MaxValue = -1; parser.AddOption(port); parser.Parse(new string[] { "--port", "-1" }); Assert.Equal(-1, port.Value); }
public void tooSmallParameterThrowsException() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); parser.AddOption(port); Assert.Throws<ParsingException>( delegate { parser.Parse(new string[] { "--port", Int64.MinValue.ToString() }); }); }
public void parameterTypeNoneFact() { CommandLineIntOption port = new CommandLineIntOption("port"); port.ParameterType = ParameterType.None; parser.AddOption(port); parser.Parse(new string[] { "--port", "8080" }); Assert.Null(port.Value); }
public void parameterTypeOptionalFact() { CommandLineIntOption port = new CommandLineIntOption("port"); port.ParameterType = ParameterType.Optional; parser.AddOption(port); parser.Parse(new string[] { "--port", "8080" }); Assert.Equal(8080, port.Value); }
public void nullParameterThrowsException() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); parser.AddOption(port); parser.Parse(new string[] { "--port", null }); Assert.Equal(0, port.Value); }
public void missingParameterTypeOptionalFact() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); port.ParameterType = ParameterType.Optional; parser.AddOption(port); parser.Parse(new string[] { "-p" }); Assert.Null(port.Value); }
public void minValueFact() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); port.MinValue = 1; port.ParameterType = ParameterType.Optional; parser.AddOption(port); parser.Parse(new string[] { "-p", Int32.MaxValue.ToString() }); Assert.Equal(Int32.MaxValue, port.Value); }
public void minValueBorderFact() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); port.ParameterType = ParameterType.Optional; port.MinValue = 1; parser.AddOption(port); parser.Parse(new string[] { "-p1"}); Assert.Equal(1, port.Value); }
public void minmaxValueFact() { CommandLineIntOption port = new CommandLineIntOption("port", "p"); port.MaxValue = 1; port.MinValue = -1; parser.AddOption(port); parser.Parse(new string[] { "--port", "0" }); Assert.Equal(0, port.Value); }