public void TestFlagParsingError() { string[] args = new string[] { "-myintflag=", "--mystringflag", "test.txt", "-myintflag=10", "-myboolFlag" }; var flags = new Parser(); var intFlag = flags.AddIntFlag("myintflag", 0, "An integer flag"); // defaults to 0 var stringFlag = flags.AddStringFlag("mystringflag", "nothing", "A string flag"); // defaults to "nothing" var boolFlag = flags.AddBoolFlag("myboolFlag", false, "A bool flag"); // defaults to false. flags.Parse(args); Assert.IsTrue(flags.HasErrors); // The parser breaks once an error is enountered so these values would NOT be set FlagValue <string> flagString = flags["mystringflag"] as FlagValue <string>; Assert.AreNotEqual("test.txt", flagString.Value); FlagValue <bool> flagBool = flags["myboolFlag"] as FlagValue <bool>; Assert.AreNotEqual(true, flagBool.Value); FlagValue <int> flagInt = flags["myintflag"] as FlagValue <int>; Assert.AreNotEqual(10, flagInt.Value); }
public void TestSetup() { parser = new Parser(); stringFlag = parser.AddStringFlag("MyStringFlag", ""); intFlag = parser.AddIntFlag("MyIntFlag", 0); boolFlag = parser.AddBoolFlag("MyBoolFlag", false); }
public void TestFlagParsing() { string[] args = new string[] { "--mystringflag", "test.txt", "-myintflag=10", "-myboolFlag" }; var flags = new Parser(); var intFlag = flags.AddIntFlag("myintflag", 0, "An integer flag"); // defaults to 0 var stringFlag = flags.AddStringFlag("mystringflag", "nothing", "A string flag"); // defaults to "nothing" var boolFlag = flags.AddBoolFlag("myboolFlag", false, "A bool flag"); // defaults to false. flags.Parse(args); Assert.IsFalse(flags.HasErrors); FlagValue <string> flagString = flags["mystringflag"] as FlagValue <string>; Assert.AreEqual("test.txt", flagString.Value); FlagValue <bool> flagBool = flags["myboolFlag"] as FlagValue <bool>; Assert.AreEqual(true, flagBool.Value); FlagValue <int> flagInt = flags["myintflag"] as FlagValue <int>; Assert.AreEqual(10, flagInt.Value); }