Exemple #1
0
        public void DerivedType()
        {
            bool help = false;
            var  p    = new CiOptionSet()
            {
                { "h|help", v => help = v != null },
            };

            p.Parse(_("-H"));
            Assert.AreEqual(help, true);
            help = false;
            p.Parse(_("-HELP"));
            Assert.AreEqual(help, true);

            Assert.AreEqual(p.GetOptionForName("h"), p [0]);
            Assert.AreEqual(p.GetOptionForName("help"), p [0]);
            Assert.AreEqual(p.GetOptionForName("invalid"), null);

            Assert.That(() => p.Add("N|NUM=", (int n) => {}), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException), "prototypes must be null!",
            //      p, v => { v.Add ("N|NUM=", (int n) => {}); });
            Assert.That(() => p.GetOptionForName(null), Throws.TypeOf <ArgumentNullException>());
            // Utils.AssertException (typeof(ArgumentNullException),
            //      "Argument cannot be null.\nParameter name: option",
            //      p, v => { v.GetOptionForName (null); });
        }
        public void DerivedType()
        {
            bool help = false;
            var  p    = new CiOptionSet()
            {
                { "h|help", v => help = v != null },
            };

            p.Parse(_("-H"));
            Assert.AreEqual(help, true);
            help = false;
            p.Parse(_("-HELP"));
            Assert.AreEqual(help, true);

            Assert.AreEqual(p.GetOptionForName("h"), p[0]);
            Assert.AreEqual(p.GetOptionForName("help"), p[0]);
            Assert.AreEqual(p.GetOptionForName("invalid"), null);

            Utils.Assert <ArgumentException>("prototypes must be null!", () => p.Add("N|NUM=", (int n) => { }));
            Utils.AssertArgumentNullException("option", () => p.GetOptionForName(null));
        }
Exemple #3
0
        public void DerivedType()
        {
            bool help = false;
            var  p    = new CiOptionSet()
            {
                { "h|help", v => help = v != null },
            };

            p.Parse(_("-H"));
            Assert.AreEqual(help, true);
            help = false;
            p.Parse(_("-HELP"));
            Assert.AreEqual(help, true);

            Assert.AreEqual(p["h"], p[0]);
            Assert.AreEqual(p["help"], p[0]);
            Assert.Throws(Is.AssignableTo(typeof(KeyNotFoundException)), () => { var tmp = p["invalid"]; Console.Write(tmp); });

            Utils.AssertException(typeof(ArgumentException), "prototypes must be null!",
                                  p, v => { v.Add("N|NUM=", (int n) => { }); });
            Assert.That(() => { var ignore = p[null]; Console.Write(ignore); }, Throws.InstanceOf <ArgumentNullException>());
        }
        public void OptionParts()
        {
            var p = new CiOptionSet();

            p.CheckOptionParts("A", false, null, null, null, null);
            p.CheckOptionParts("A=B", false, null, null, null, null);
            p.CheckOptionParts("-A=B", true, "-", "A", "=", "B");
            p.CheckOptionParts("-A:B", true, "-", "A", ":", "B");
            p.CheckOptionParts("--A=B", true, "--", "A", "=", "B");
            p.CheckOptionParts("--A:B", true, "--", "A", ":", "B");
            p.CheckOptionParts("/A=B", true, "/", "A", "=", "B");
            p.CheckOptionParts("/A:B", true, "/", "A", ":", "B");
            p.CheckOptionParts("-A=B=C", true, "-", "A", "=", "B=C");
            p.CheckOptionParts("-A:B=C", true, "-", "A", ":", "B=C");
            p.CheckOptionParts("-A:B:C", true, "-", "A", ":", "B:C");
            p.CheckOptionParts("--A=B=C", true, "--", "A", "=", "B=C");
            p.CheckOptionParts("--A:B=C", true, "--", "A", ":", "B=C");
            p.CheckOptionParts("--A:B:C", true, "--", "A", ":", "B:C");
            p.CheckOptionParts("/A=B=C", true, "/", "A", "=", "B=C");
            p.CheckOptionParts("/A:B=C", true, "/", "A", ":", "B=C");
            p.CheckOptionParts("/A:B:C", true, "/", "A", ":", "B:C");
            p.CheckOptionParts("-AB=C", true, "-", "AB", "=", "C");
            p.CheckOptionParts("-AB:C", true, "-", "AB", ":", "C");
        }
        public void DerivedType()
        {
            bool help = false;
            var  p    = new CiOptionSet()
            {
                { "h|help", v => help = v != null },
            };

            p.Parse(_("-H"));
            Assert.AreEqual(help, true);
            help = false;
            p.Parse(_("-HELP"));
            Assert.AreEqual(help, true);

            Assert.AreEqual(p.GetOptionForName("h"), p [0]);
            Assert.AreEqual(p.GetOptionForName("help"), p [0]);
            Assert.AreEqual(p.GetOptionForName("invalid"), null);

            Utils.AssertException(typeof(ArgumentException), "prototypes must be null!",
                                  p, v => { v.Add("N|NUM=", (int n) => {}); });
            Utils.AssertException(typeof(ArgumentNullException),
                                  $"Value cannot be null.{Environment.NewLine}Parameter name: option",
                                  p, v => { v.GetOptionForName(null); });
        }