Beispiel #1
0
        public void Exceptions()
        {
            object p = null;

            Assert.That(() => new DefaultOption(null, null), Throws.InstanceOf <ArgumentNullException>());
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot be the empty string.\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Empty option names are not supported.\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a|b||c=", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Conflicting option types: '=' vs. ':'.\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a=|b:", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "The default option handler '<>' cannot require values.\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("<>=", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "The default option handler '<>' cannot require values.\r\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.\r\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),
                                  "Specified argument was out of the range of valid values.\r\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.\r\nParameter name: maxValueCount",
                                  p, v => { new DefaultOption("a=", null, 0); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a={\".\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a=}\".\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a=}", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a={{}}\".\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={{}}", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a={}}\".\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={}}", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a={}{\".\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={}{", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot provide key/value separators for Options taking 1 value(s).\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a==", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot provide key/value separators for Options taking 1 value(s).\r\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={}", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot provide key/value separators for Options taking 1 value(s).\r\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.InstanceOf<ArgumentNullException>());
     Utils.AssertException(typeof(ArgumentException),
             "Cannot be the empty string.\r\nParameter name: prototype",
             p, v => { new DefaultOption("", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Empty option names are not supported.\r\nParameter name: prototype",
             p, v => { new DefaultOption("a|b||c=", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Conflicting option types: '=' vs. ':'.\r\nParameter name: prototype",
             p, v => { new DefaultOption("a=|b:", null); });
     Utils.AssertException(typeof(ArgumentException),
             "The default option handler '<>' cannot require values.\r\nParameter name: prototype",
             p, v => { new DefaultOption("<>=", null); });
     Utils.AssertException(typeof(ArgumentException),
             "The default option handler '<>' cannot require values.\r\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.\r\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),
             "Specified argument was out of the range of valid values.\r\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.\r\nParameter name: maxValueCount",
             p, v => { new DefaultOption("a=", null, 0); });
     Utils.AssertException(typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a={\".\r\nParameter name: prototype",
             p, v => { new DefaultOption("a={", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a=}\".\r\nParameter name: prototype",
             p, v => { new DefaultOption("a=}", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a={{}}\".\r\nParameter name: prototype",
             p, v => { new DefaultOption("a={{}}", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a={}}\".\r\nParameter name: prototype",
             p, v => { new DefaultOption("a={}}", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Ill-formed name/value separator found in \"a={}{\".\r\nParameter name: prototype",
             p, v => { new DefaultOption("a={}{", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Cannot provide key/value separators for Options taking 1 value(s).\r\nParameter name: prototype",
             p, v => { new DefaultOption("a==", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Cannot provide key/value separators for Options taking 1 value(s).\r\nParameter name: prototype",
             p, v => { new DefaultOption("a={}", null); });
     Utils.AssertException(typeof(ArgumentException),
             "Cannot provide key/value separators for Options taking 1 value(s).\r\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], "/");
             });
 }