public void TestParseWithFlagExclusions() { OptionTable T = new OptionTable(InfoTable); // Exclude flag3 to avoid parsing as OPT_ID.OPT_SLASH_C. InputArgumentList AL = T.ParseArgs(Args, out int MAI, out int MAC, /*FlagsToInclude=*/ 0, /*FlagsToExclude=*/ (int)OptionFlags.OptFlag3); Assert.IsTrue(AL.HasArg(OPT_ID.OPT_A)); Assert.IsTrue(AL.HasArg(OPT_ID.OPT_C)); Assert.IsTrue(!AL.HasArg(OPT_ID.OPT_SLASH_C)); // Exclude flag1 to avoid parsing as OPT_ID.OPT_C. AL = T.ParseArgs(Args, out MAI, out MAC, /*FlagsToInclude=*/ 0, /*FlagsToExclude=*/ (int)OptionFlags.OptFlag1); Assert.IsTrue(AL.HasArg(OPT_ID.OPT_B)); Assert.IsTrue(!AL.HasArg(OPT_ID.OPT_C)); Assert.IsTrue(AL.HasArg(OPT_ID.OPT_SLASH_C)); string[] NewArgs = new string[] { "/C", "foo", "--C=bar" }; AL = T.ParseArgs(NewArgs, out MAI, out MAC); Assert.IsTrue(AL.HasArg(OPT_ID.OPT_SLASH_C)); Assert.IsTrue(AL.HasArg(OPT_ID.OPT_C)); Assert.IsTrue("foo" == AL.GetLastArgValue(OPT_ID.OPT_SLASH_C)); Assert.IsTrue("bar" == AL.GetLastArgValue(OPT_ID.OPT_C)); }
public void TestOptionParsing() { OptionTable T = new OptionTable(InfoTable); int FlagsToInclude = 0; int FlagsToExclude = 0; InputArgumentList al = T.ParseArgs(Args, out int missingArgIndex, out int missingArgCount, FlagsToInclude, FlagsToExclude); // Check they all exist. Assert.IsTrue(al.HasArg(OPT_ID.OPT_A)); Assert.IsTrue(al.HasArg(OPT_ID.OPT_B)); Assert.IsTrue(al.HasArg(OPT_ID.OPT_C)); Assert.IsTrue(al.HasArg(OPT_ID.OPT_D)); Assert.IsTrue(al.HasArg(OPT_ID.OPT_E)); Assert.IsTrue(al.HasArg(OPT_ID.OPT_F)); Assert.IsTrue(al.HasArg(OPT_ID.OPT_G)); // Check the values. Assert.IsTrue("hi" == al.GetLastArgValue(OPT_ID.OPT_B)); Assert.IsTrue("bye" == al.GetLastArgValue(OPT_ID.OPT_C)); Assert.IsTrue("adena" == al.GetLastArgValue(OPT_ID.OPT_D)); List <string> Es = al.GetAllArgValues(OPT_ID.OPT_E); Assert.IsTrue("apple" == Es[0]); Assert.IsTrue("bloom" == Es[1]); Assert.IsTrue("42" == al.GetLastArgValue(OPT_ID.OPT_F)); List <string> Gs = al.GetAllArgValues(OPT_ID.OPT_G); Assert.IsTrue("chuu" == Gs[0]); Assert.IsTrue("2" == Gs[1]); // Check the help text. StringBuilder RSO = new StringBuilder(); T.PrintHelp(RSO, "test", "title!"); string Help = RSO.ToString(); Assert.IsTrue(Help.Length != Help.IndexOf("-A", StringComparison.Ordinal)); // Test aliases. var Cs = al.Filtered(OPT_ID.OPT_C); Assert.IsTrue(Cs.First() != Cs.Last()); Assert.IsTrue("desu" == Cs.First().GetValue()); List <string> ASL = new List <string>(); Cs.First().Render(al, ASL); Assert.IsTrue(2u == ASL.Count); Assert.IsTrue("-C" == ASL[0]); Assert.IsTrue("desu" == ASL[1]); }