Example #1
0
        public void Should_give_spec_of_many_types(string desc, string flag, object val, Type expectedType)
        {
            var specs = new List <Arg> {
                new Arg(desc, flag, val)
            };
            var parser = new ArgsParser(specs);

            Assert.AreEqual(1, parser.Spec.Count());
            Assert.AreEqual(expectedType, parser.Spec[flag].Type);
        }
Example #2
0
        public void Should_throw_argexecption_when_type_is_incorrect()
        {
            var specs = new List <Arg>
            {
                new Arg("Port", "p", 0)
            };

            var parser = new ArgsParser(specs);

            Assert.Throws <ArgumentException>(() => parser.Parse("-p une_string!".Split(' ')));
        }
Example #3
0
        public void Should_return_true_when_boolean_flag_is_present()
        {
            var specs = new List <Arg> {
                new Arg("Logging", "l", false)
            };

            var parser = new ArgsParser(specs);

            var argsResult = parser.Parse(new string[] { "-l" });

            Assert.IsTrue(argsResult.ContainsKey("l"));
            Assert.AreEqual(true, argsResult["l"].Value);
        }
Example #4
0
        public void Should_return_parsed_arg_value()
        {
            var specs = new List <Arg> {
                new Arg("Port", "p", 0)
            };

            var parser = new ArgsParser(specs);

            var argsResult = parser.Parse(new string[] { "-p", "8080" });

            Assert.IsTrue(argsResult.ContainsKey("p"));
            Assert.AreEqual(8080, argsResult["p"].Value);
        }
Example #5
0
        public void Should_return_default_values_from_specs()
        {
            var specs = new List <Arg> {
                new Arg("Port", "p", 80)
            };

            var parser = new ArgsParser(specs);

            var argsResult = parser.Parse(new string[] {});

            Assert.IsTrue(argsResult.ContainsKey("p"));
            Assert.AreEqual(specs[0].Value, argsResult["p"].Value);
        }
Example #6
0
        public void Should_parsed_many_arg_values()
        {
            var specs = new List <Arg>
            {
                new Arg("Logging", "l", false),
                new Arg("Port", "p", 0),
                new Arg("Directory", "d", string.Empty)
            };

            var parser = new ArgsParser(specs);

            var argsResult = parser.Parse("-l -p 8080 -d /usr/logs".Split(' '));

            Assert.AreEqual(true, argsResult["l"].Value);
            Assert.AreEqual(8080, argsResult["p"].Value);
            Assert.AreEqual("/usr/logs", argsResult["d"].Value);
        }
Example #7
0
        public void Should_take_spec_when_instanced()
        {
            var parser = new ArgsParser(new List <Arg>());

            Assert.AreEqual(0, parser.Spec.Count());
        }