Beispiel #1
0
 public void Exceptions()
 {
     object p = null;
     Utils.AssertException (typeof(ArgumentNullException),
             "Argument cannot be null.\nParameter name: prototype",
             p, v => { new DefaultOption (null, null); });
     Utils.AssertException (typeof(ArgumentException),
             "Cannot be the empty string.\nParameter name: prototype",
             p, v => { new DefaultOption ("", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Empty option names are not supported.\nParameter name: prototype",
             p, v => { new DefaultOption ("a|b||c=", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Conflicting option types: '=' vs. ':'.\nParameter name: prototype",
             p, v => { new DefaultOption ("a=|b:", null); });
     Utils.AssertException (typeof(ArgumentException),
             "The default option handler '<>' cannot require values.\nParameter name: prototype",
             p, v => { new DefaultOption ("<>=", null); });
     Utils.AssertException (typeof(ArgumentException),
             "The default option handler '<>' cannot require values.\nParameter name: prototype",
             p, v => { new DefaultOption ("<>:", null); });
     Utils.AssertException (null, null,
             p, v => { new DefaultOption ("t|<>=", null, 1); });
     Utils.AssertException (typeof(ArgumentException),
             "The default option handler '<>' cannot require values.\nParameter name: prototype",
             p, v => { new DefaultOption ("t|<>=", null, 2); });
     Utils.AssertException (null, null,
             p, v => { new DefaultOption ("a|b=", null, 2); });
     Utils.AssertException (typeof(ArgumentOutOfRangeException),
             "Argument is out of range.\nParameter name: maxValueCount",
             p, v => { new DefaultOption ("a", null, -1); });
     Utils.AssertException (typeof(ArgumentException),
             "Cannot provide maxValueCount of 0 for OptionValueType.Required or " +
                 "OptionValueType.Optional.\nParameter name: maxValueCount",
             p, v => { new DefaultOption ("a=", null, 0); });
     Utils.AssertException (typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a={\".\nParameter name: prototype",
             p, v => { new DefaultOption ("a={", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a=}\".\nParameter name: prototype",
             p, v => { new DefaultOption ("a=}", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a={{}}\".\nParameter name: prototype",
             p, v => { new DefaultOption ("a={{}}", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a={}}\".\nParameter name: prototype",
             p, v => { new DefaultOption ("a={}}", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a={}{\".\nParameter name: prototype",
             p, v => { new DefaultOption ("a={}{", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
             p, v => { new DefaultOption ("a==", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
             p, v => { new DefaultOption ("a={}", null); });
     Utils.AssertException (typeof(ArgumentException),
             "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
             p, v => { new DefaultOption ("a=+-*/", null); });
     Utils.AssertException (null, null,
             p, v => { new DefaultOption ("a", null, 0); });
     Utils.AssertException (null, null,
             p, v => { new DefaultOption ("a", null, 0); });
     Utils.AssertException (null, null,
             p, v => {
                 var d = new DefaultOption ("a", null);
                 Assert.AreEqual (d.GetValueSeparators ().Length, 0);
             });
     Utils.AssertException (null, null,
             p, v => {
                 var d = new DefaultOption ("a=", null, 1);
                 string[] s = d.GetValueSeparators ();
                 Assert.AreEqual (s.Length, 0);
             });
     Utils.AssertException (null, null,
             p, v => {
                 var d = new DefaultOption ("a=", null, 2);
                 string[] s = d.GetValueSeparators ();
                 Assert.AreEqual (s.Length, 2);
                 Assert.AreEqual (s [0], ":");
                 Assert.AreEqual (s [1], "=");
             });
     Utils.AssertException (null, null,
             p, v => {
                 var d = new DefaultOption ("a={}", null, 2);
                 string[] s = d.GetValueSeparators ();
                 Assert.AreEqual (s.Length, 0);
             });
     Utils.AssertException (null, null,
             p, v => {
                 var d = new DefaultOption ("a={-->}{=>}", null, 2);
                 string[] s = d.GetValueSeparators ();
                 Assert.AreEqual (s.Length, 2);
                 Assert.AreEqual (s [0], "-->");
                 Assert.AreEqual (s [1], "=>");
             });
     Utils.AssertException (null, null,
             p, v => {
                 var d = new DefaultOption ("a=+-*/", null, 2);
                 string[] s = d.GetValueSeparators ();
                 Assert.AreEqual (s.Length, 4);
                 Assert.AreEqual (s [0], "+");
                 Assert.AreEqual (s [1], "-");
                 Assert.AreEqual (s [2], "*");
                 Assert.AreEqual (s [3], "/");
             });
 }
Beispiel #2
0
        public void Exceptions()
        {
            object p = null;

            Assert.That(() => new DefaultOption(null, null), Throws.TypeOf <ArgumentNullException>());
            // Utils.AssertException (typeof(ArgumentNullException),
            //      "Argument cannot be null.\nParameter name: prototype",
            //      p, v => { new DefaultOption (null, null); });
            Assert.That(() => new DefaultOption("", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Cannot be the empty string.\nParameter name: prototype",
            //      p, v => { new DefaultOption ("", null); });
            Assert.That(() => new DefaultOption("a|b||c=", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Empty option names are not supported.\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a|b||c=", null); });
            Assert.That(() => new DefaultOption("a=|b:", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Conflicting option types: '=' vs. ':'.\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a=|b:", null); });
            Assert.That(() => new DefaultOption("<>=", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "The default option handler '<>' cannot require values.\nParameter name: prototype",
            //      p, v => { new DefaultOption ("<>=", null); });
            Assert.That(() => new DefaultOption("<>:", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "The default option handler '<>' cannot require values.\nParameter name: prototype",
            //      p, v => { new DefaultOption ("<>:", null); });
            Assert.That(() => new DefaultOption("t|<>=", null), Throws.Nothing);
            // Utils.AssertException (null, null,
            //      p, v => { new DefaultOption ("t|<>=", null, 1); });
            Assert.That(() => new DefaultOption("t|<>=", null, 2), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "The default option handler '<>' cannot require values.\nParameter name: prototype",
            //      p, v => { new DefaultOption ("t|<>=", null, 2); });
            Assert.That(() => new DefaultOption("a|b=", null, 2), Throws.Nothing);
            // Utils.AssertException (null, null,
            //      p, v => { new DefaultOption ("a|b=", null, 2); });
            Assert.That(() => new DefaultOption("a", null, -1), Throws.TypeOf <ArgumentOutOfRangeException>());
            // Utils.AssertException (typeof(ArgumentOutOfRangeException),
            //      "Argument is out of range.\nParameter name: maxValueCount",
            //      p, v => { new DefaultOption ("a", null, -1); });
            Assert.That(() => new DefaultOption("a=", null, 0), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Cannot provide maxValueCount of 0 for OptionValueType.Required or " +
            //          "OptionValueType.Optional.\nParameter name: maxValueCount",
            //      p, v => { new DefaultOption ("a=", null, 0); });
            Assert.That(() => new DefaultOption("a={", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Ill-formed name/value separator found in \"a={\".\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a={", null); });
            Assert.That(() => new DefaultOption("a=}", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Ill-formed name/value separator found in \"a=}\".\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a=}", null); });
            Assert.That(() => new DefaultOption("a={{}}", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Ill-formed name/value separator found in \"a={{}}\".\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a={{}}", null); });
            Assert.That(() => new DefaultOption("a={}}", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Ill-formed name/value separator found in \"a={}}\".\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a={}}", null); });
            Assert.That(() => new DefaultOption("a={}{", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Ill-formed name/value separator found in \"a={}{\".\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a={}{", null); });
            Assert.That(() => new DefaultOption("a==", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a==", null); });
            Assert.That(() => new DefaultOption("a={}", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a={}", null); });
            Assert.That(() => new DefaultOption("a=+-*/", null), Throws.TypeOf <ArgumentException>());
            // Utils.AssertException (typeof(ArgumentException),
            //      "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
            //      p, v => { new DefaultOption ("a=+-*/", null); });
            Assert.That(() => new DefaultOption("a", null, 0), Throws.Nothing);
            // Utils.AssertException (null, null,
            //      p, v => { new DefaultOption ("a", null, 0); });
            Assert.That(() => new DefaultOption("a", null, 0), Throws.Nothing);
            // Utils.AssertException (null, null,
            //      p, v => { new DefaultOption ("a", null, 0); });
            DefaultOption d;

            string[] s;
            d = new DefaultOption("a", null);
            Assert.AreEqual(d.GetValueSeparators().Length, 0);
            // Utils.AssertException (null, null,
            //      p, v => {
            //          var d = new DefaultOption ("a", null);
            //          Assert.AreEqual (d.GetValueSeparators ().Length, 0);
            //      });
            Assert.That(() => new DefaultOption("t|<>=", null), Throws.Nothing);
            d = new DefaultOption("a=", null, 1);
            s = d.GetValueSeparators();
            Assert.AreEqual(s.Length, 0);
            // Utils.AssertException (null, null,
            //      p, v => {
            //          var d = new DefaultOption ("a=", null, 1);
            //          string[] s = d.GetValueSeparators ();
            //          Assert.AreEqual (s.Length, 0);
            //      });
            d = new DefaultOption("a=", null, 2);
            s = d.GetValueSeparators();
            Assert.AreEqual(s.Length, 2);
            Assert.AreEqual(s [0], ":");
            Assert.AreEqual(s [1], "=");
            // Utils.AssertException (null, null,
            //      p, v => {
            //          var d = new DefaultOption ("a=", null, 2);
            //          string[] s = d.GetValueSeparators ();
            //          Assert.AreEqual (s.Length, 2);
            //          Assert.AreEqual (s [0], ":");
            //          Assert.AreEqual (s [1], "=");
            //      });
            d = new DefaultOption("a={}", null, 2);
            s = d.GetValueSeparators();
            Assert.AreEqual(s.Length, 0);
            // Utils.AssertException (null, null,
            //      p, v => {
            //          var d = new DefaultOption ("a={}", null, 2);
            //          string[] s = d.GetValueSeparators ();
            //          Assert.AreEqual (s.Length, 0);
            //      });
            d = new DefaultOption("a={-->}{=>}", null, 2);
            s = d.GetValueSeparators();
            Assert.AreEqual(s.Length, 2);
            Assert.AreEqual(s [0], "-->");
            Assert.AreEqual(s [1], "=>");
            // Utils.AssertException (null, null,
            //      p, v => {
            //          var d = new DefaultOption ("a={-->}{=>}", null, 2);
            //          string[] s = d.GetValueSeparators ();
            //          Assert.AreEqual (s.Length, 2);
            //          Assert.AreEqual (s [0], "-->");
            //          Assert.AreEqual (s [1], "=>");
            //      });
            d = new DefaultOption("a=+-*/", null, 2);
            s = d.GetValueSeparators();
            Assert.AreEqual(s.Length, 4);
            Assert.AreEqual(s [0], "+");
            Assert.AreEqual(s [1], "-");
            Assert.AreEqual(s [2], "*");
            Assert.AreEqual(s [3], "/");
            // Utils.AssertException (null, null,
            //      p, v => {
            //          var d = new DefaultOption ("a=+-*/", null, 2);
            //          string[] s = d.GetValueSeparators ();
            //          Assert.AreEqual (s.Length, 4);
            //          Assert.AreEqual (s [0], "+");
            //          Assert.AreEqual (s [1], "-");
            //          Assert.AreEqual (s [2], "*");
            //          Assert.AreEqual (s [3], "/");
            //      });
        }