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

            Utils.Assert <ArgumentException>("prototypes must be null!", () => p.Add("N|NUM=", (int n) => { }));
            Utils.AssertArgumentNullException("option", () => p.GetOptionForName(null));
        }
Exemplo n.º 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>());
        }
Exemplo n.º 4
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);

            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); });
        }