public void TestMethodDoubleValues1() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); var c = p.AddPositionalParameter("c"); p.Parse(new string[] { "-2.1", "0.0", "1.1" }); Assert.AreEqual(-2.1, a.GetDouble()); Assert.AreEqual(0, b.GetDouble()); Assert.AreEqual(1.1, c.GetDouble()); }
public void TestMethodEnumValues1() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); var c = p.AddPositionalParameter("c"); p.Parse(new string[] { "Choice1", "choICE1", "choice2" }); Assert.AreEqual(EFOO.Choice1, a.GetEnum <EFOO>()); Assert.AreEqual(EFOO.Choice1, b.GetEnum <EFOO>()); Assert.AreEqual(EFOO.Choice2, c.GetEnum <EFOO>()); }
public void TestTwoPositionalArgs() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); string[] tokens = { "1", "2" }; p.Parse(tokens); Assert.AreEqual(a.Text, "1"); Assert.AreEqual(b.Text, "2"); }
public void TestMethodYesNoValues1() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); var c = p.AddPositionalParameter("c"); var d = p.AddPositionalParameter("d"); p.Parse(new string[] { "y", "yes", "no", "n" }); Assert.AreEqual(true, a.GetYesNo()); Assert.AreEqual(true, b.GetYesNo()); Assert.AreEqual(false, c.GetYesNo()); Assert.AreEqual(false, d.GetYesNo()); }
public void TestPostParseCallbacks() { int a1_v = 0; int a2_v = 0; int b_v = 0; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); var c = p.AddNamedParameter("c", Isotope.CommandLine.ParameterRequirement.NotRequired); a.OnPostParse += (parser, arg) => { a1_v = 1; }; a.OnPostParse += (parser, arg) => { a2_v = 2; }; b.OnPostParse += (parser, arg) => { b_v = 3; }; string[] tokens = { "1", "x1", "-c", "3", "x2", "-b", "2", "x3", "x4" }; p.Parse(tokens); Assert.AreEqual("1", a.Text); Assert.AreEqual("2", b.Text); Assert.AreEqual("3", c.Text); Assert.AreEqual(1, a1_v); Assert.AreEqual(2, a2_v); Assert.AreEqual(3, b_v); }
public void TestCallbacksCalledOnlyOnSuccessfulParsing() { int a1_v = 0; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); a.OnPostParse += (parser, arg) => { a1_v = 1; }; string[] tokens = { "1", "x1" }; // b is missing try { p.Parse(tokens); } catch (Isotope.CommandLine.MissingRequiredParameterException) { // this is ok } catch (System.Exception) { // this is not throw; } Assert.AreEqual("1", a.Text); Assert.AreEqual(0, a1_v); }
public void TestDuplicatePositionalArgNames() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); p.AddPositionalParameter("a"); try{ p.AddPositionalParameter("a"); } catch (Isotope.CommandLine.GrammarException) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestDuplicatePositionalArgNames() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); p.AddPositionalParameter("a"); try{p.AddPositionalParameter("a");} catch (Isotope.CommandLine.GrammarException ) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestMissingPositionalArg2() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); string[] tokens = { "1" }; try { p.Parse(tokens); } catch (Isotope.CommandLine.MissingRequiredParameterException) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestExcess3() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); string[] tokens = { "1", "x1", "-b", "2", "x2" }; p.Parse(tokens); Assert.AreEqual("1", a.Text); Assert.AreEqual("2", b.Text); }
public void TestUnhandlesTokens1() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); string[] tokens = { "1" }; p.Parse(tokens); Assert.AreEqual(p.FindParameter("a"), a); Assert.AreEqual(p.FindParameter("x"), null); Assert.AreEqual(a.Text, "1"); }
public void TestValuesForEmptyStringParameterValues() { // positional args always take precedence in order over named args, even if they are named on the command line var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); string[] tokens = { "", "-b", "" }; p.Parse(tokens); Assert.AreEqual("", a.Text); Assert.AreEqual("", b.Text); }
public void TestNamedOptionalWithValue() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); var c = p.AddNamedParameter("c", Isotope.CommandLine.ParameterRequirement.NotRequired); string[] tokens = { "1", "x1", "-c", "3", "x2", "-b", "2", "x3", "x4" }; p.Parse(tokens); Assert.AreEqual("1", a.Text); Assert.AreEqual("2", b.Text); Assert.AreEqual("3", c.Text); }
public void Test2PossibleValue() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); a.PossibleValues = new string[] { "Hello", "World" }; p.Parse(new string[] { "Hello" }); Assert.AreEqual("Hello", a.Text); p.Parse(new string[] { "World" }); Assert.AreEqual("World", a.Text); p.Parse(new string[] { "helLO" }); Assert.AreEqual("helLO", a.Text); }
public void Test0PossibleValues() { // verify that adding zero possible values is possible var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); a.PossibleValues = new string[] {}; string[] tokens = { "foo" }; p.Parse(tokens); Assert.AreEqual("foo", a.Text); }
public void Test1PossibleValue() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); a.PossibleValues = new string[] { "Hello" }; try { p.Parse(new string[] { "foo" }); } catch (Isotope.CommandLine.InvalidParameterValueException) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestMethodEnumValues2() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); p.Parse(new string[] { "foo" }); try { var n = a.GetEnum <EFOO>(); } catch (System.ArgumentException) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestMisingPositionalValueThrowsException() { // verifies that when the text value is missing, an exception is thrown bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); try { string s = a.Text; } catch (Isotope.CommandLine.RuntimeErrorException) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestPositionArgsTakePrecedence() { // positional args always take precedence in order over named args, even if they are named on the command line var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); var c = p.AddNamedParameter("c", Isotope.CommandLine.ParameterRequirement.NotRequired); string[] tokens = { "-c", "t1", "t2", "-b", "bv", "t5", "t6" }; p.Parse(tokens); Assert.AreEqual("-c", a.Text); Assert.AreEqual("bv", b.Text); Assert.IsFalse(c.HasValue); var unnassigned = p.GetUnassignedTokens(); Assert.AreEqual(4, unnassigned.Count); Assert.AreEqual("t1", unnassigned[0]); Assert.AreEqual("t2", unnassigned[1]); Assert.AreEqual("t5", unnassigned[2]); Assert.AreEqual("t6", unnassigned[3]); }
public void TestPositionArgsTakePrecedence() { // positional args always take precedence in order over named args, even if they are named on the command line var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); var c = p.AddNamedParameter("c", Isotope.CommandLine.ParameterRequirement.NotRequired); string[] tokens = {"-c", "t1", "t2", "-b", "bv", "t5", "t6"}; p.Parse(tokens); Assert.AreEqual("-c", a.Text); Assert.AreEqual("bv", b.Text); Assert.IsFalse(c.HasValue); var unnassigned = p.GetUnassignedTokens(); Assert.AreEqual(4, unnassigned.Count); Assert.AreEqual("t1", unnassigned[0]); Assert.AreEqual("t2", unnassigned[1]); Assert.AreEqual("t5", unnassigned[2]); Assert.AreEqual("t6", unnassigned[3]); }
public void TestPostParseCallbacks() { int a1_v = 0; int a2_v = 0; int b_v = 0; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); var c = p.AddNamedParameter("c", Isotope.CommandLine.ParameterRequirement.NotRequired); a.OnPostParse += (parser, arg) => { a1_v = 1; }; a.OnPostParse += (parser, arg) => { a2_v = 2; }; b.OnPostParse += (parser, arg) => { b_v = 3; }; string[] tokens = {"1", "x1", "-c", "3", "x2", "-b", "2", "x3", "x4"}; p.Parse(tokens); Assert.AreEqual("1", a.Text); Assert.AreEqual("2", b.Text); Assert.AreEqual("3", c.Text); Assert.AreEqual(1, a1_v); Assert.AreEqual(2, a2_v); Assert.AreEqual(3, b_v); }
public void TestMethodEnumValues1() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); var c = p.AddPositionalParameter("c"); p.Parse(new string[] {"Choice1", "choICE1", "choice2"}); Assert.AreEqual(EFOO.Choice1, a.GetEnum<EFOO>()); Assert.AreEqual(EFOO.Choice1, b.GetEnum<EFOO>()); Assert.AreEqual(EFOO.Choice2, c.GetEnum<EFOO>()); }
public void TestMethodDoubleValues1() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); var c = p.AddPositionalParameter("c"); p.Parse(new string[] {"-2.1", "0.0", "1.1"}); Assert.AreEqual(-2.1, a.GetDouble()); Assert.AreEqual(0, b.GetDouble()); Assert.AreEqual(1.1, c.GetDouble()); }
public void Test1PossibleValue() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); a.PossibleValues = new string[] {"Hello"}; try {p.Parse(new string[] {"foo"});} catch (Isotope.CommandLine.InvalidParameterValueException ) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestCallbacksCalledOnlyOnSuccessfulParsing() { int a1_v = 0; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); a.OnPostParse += (parser, arg) => { a1_v = 1; }; string[] tokens = {"1", "x1"}; // b is missing try { p.Parse(tokens); } catch (Isotope.CommandLine.MissingRequiredParameterException) { // this is ok } catch (System.Exception) { // this is not throw; } Assert.AreEqual("1", a.Text); Assert.AreEqual(0, a1_v); }
public void TestUnhandlesTokens1() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); string[] tokens = {"1"}; p.Parse(tokens); Assert.AreEqual(p.FindParameter("a"), a); Assert.AreEqual(p.FindParameter("x"), null); Assert.AreEqual(a.Text, "1"); }
public void TestValuesForEmptyStringParameterValues() { // positional args always take precedence in order over named args, even if they are named on the command line var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); string[] tokens = {"", "-b", ""}; p.Parse(tokens); Assert.AreEqual("", a.Text); Assert.AreEqual("", b.Text); }
public void TestMisingPositionalValueThrowsException() { // verifies that when the text value is missing, an exception is thrown bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); try {string s = a.Text;} catch (Isotope.CommandLine.RuntimeErrorException ) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestCreatePositionalArg() { var p = new Isotope.CommandLine.CommandLineParser(); p.AddPositionalParameter("a"); }
public void Test0PossibleValues() { // verify that adding zero possible values is possible var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); a.PossibleValues = new string[] {}; string[] tokens = {"foo"}; p.Parse(tokens); Assert.AreEqual("foo", a.Text); }
public void TestMissingRequiredNamedArgThrowsException() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); string[] tokens = {"1", "2"}; try {p.Parse(tokens);} catch (Isotope.CommandLine.MissingRequiredParameterException ) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void Test2PossibleValue() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); a.PossibleValues = new string[] {"Hello", "World"}; p.Parse(new string[] {"Hello"}); Assert.AreEqual("Hello", a.Text); p.Parse(new string[] {"World"}); Assert.AreEqual("World", a.Text); p.Parse(new string[] {"helLO"}); Assert.AreEqual("helLO", a.Text); }
public void TestExcess3() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); string[] tokens = {"1", "x1", "-b", "2", "x2"}; p.Parse(tokens); Assert.AreEqual("1", a.Text); Assert.AreEqual("2", b.Text); }
public void TestMethodYesNoValues1() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); var c = p.AddPositionalParameter("c"); var d = p.AddPositionalParameter("d"); p.Parse(new string[] {"y", "yes", "no", "n"}); Assert.AreEqual(true, a.GetYesNo()); Assert.AreEqual(true, b.GetYesNo()); Assert.AreEqual(false, c.GetYesNo()); Assert.AreEqual(false, d.GetYesNo()); }
public void TestCreatePositionalArg() { var p = new Isotope.CommandLine.CommandLineParser(); p.AddPositionalParameter("a"); }
public void TestMethodEnumValues2() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); p.Parse(new string[] {"foo"}); try {var n = a.GetEnum<EFOO>();} catch (System.ArgumentException ) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestNamedOptionalWithValue() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddNamedParameter("b", Isotope.CommandLine.ParameterRequirement.Required); var c = p.AddNamedParameter("c", Isotope.CommandLine.ParameterRequirement.NotRequired); string[] tokens = {"1", "x1", "-c", "3", "x2", "-b", "2", "x3", "x4"}; p.Parse(tokens); Assert.AreEqual("1", a.Text); Assert.AreEqual("2", b.Text); Assert.AreEqual("3", c.Text); }
public void TestMissingPositionalArg1() { bool caught = false; var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); string[] tokens = {}; try {p.Parse(tokens);} catch (Isotope.CommandLine.MissingRequiredParameterException ) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } }
public void TestTwoPositionalArgs() { var p = new Isotope.CommandLine.CommandLineParser(); var a = p.AddPositionalParameter("a"); var b = p.AddPositionalParameter("b"); string[] tokens = {"1", "2"}; p.Parse(tokens); Assert.AreEqual(a.Text, "1"); Assert.AreEqual(b.Text, "2"); }