Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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>());
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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");
            }
        }
Exemplo n.º 8
0
        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");
            }

        }
Exemplo n.º 9
0
        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");
            }
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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");
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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");
            }
        }
Exemplo n.º 17
0
        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");
            }
        }
Exemplo n.º 18
0
        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");
            }
        }
Exemplo n.º 19
0
        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]);
        }
Exemplo n.º 20
0
        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]);
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
 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>());
 }
Exemplo n.º 23
0
 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());
 }
Exemplo n.º 24
0
        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");
            }
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        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");
        }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        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");
            }
        }
Exemplo n.º 29
0
 public void TestCreatePositionalArg()
 {
     var p = new Isotope.CommandLine.CommandLineParser();
     p.AddPositionalParameter("a");
 }
Exemplo n.º 30
0
        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);
        }
Exemplo n.º 31
0
        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");
            }
        }
Exemplo n.º 32
0
 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);
 }
Exemplo n.º 33
0
        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);
        }
Exemplo n.º 34
0
 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());
 }
Exemplo n.º 35
0
        public void TestCreatePositionalArg()
        {
            var p = new Isotope.CommandLine.CommandLineParser();

            p.AddPositionalParameter("a");
        }
Exemplo n.º 36
0
        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");
            }
        }
Exemplo n.º 37
0
        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);
        }
Exemplo n.º 38
0
        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");
            }
        }
Exemplo n.º 39
0
        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");
        }