Exemplo n.º 1
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.º 2
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]);
        }