Beispiel #1
0
        public void MultipleOptionShouldThrow()
        {
            Option[] options = new Option[]
            {
                new Option("a", null, "TestA", "Nothing", false, multipleTimes: false)
            };
            OptionParser parser = new OptionParser(new OptionParser.Configuration(options));

            string testLine = "-a -a";

            Assert.ThrowsException <ParserException>(() => parser.ParseAll(testLine).ToList());
        }
Beispiel #2
0
        public void OptionWithArgumentAtEndShouldNotThrow()
        {
            Option[] options = new Option[]
            {
                new Option("a", null, "TestA", "Nothing", false)
            };
            OptionParser parser = new OptionParser(new OptionParser.Configuration(options));

            string testLine = "-a argument";

            parser.ParseAll(testLine).ToList();
        }
Beispiel #3
0
        public void OptionWithoutArgumentShouldFail()
        {
            Option[] options = new Option[]
            {
                new Option("a", null, "TestA", "Nothing", true)
            };
            OptionParser parser = new OptionParser(new OptionParser.Configuration(options));

            string testLine = "-a";

            Assert.ThrowsException <ParserException>(() => parser.ParseAll(testLine).ToList());
        }
Beispiel #4
0
        public void SingleSimpleLongOption()
        {
            Option[] options = new Option[]
            {
                new Option("a", "longoption", "TestA", "Nothing", false)
            };
            OptionParser parser = new OptionParser(new OptionParser.Configuration(options));

            string testLine = "--longoption";

            var result = parser.ParseAll(testLine);

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Option == options[0]);
        }
Beispiel #5
0
        public void ArgumentBetweenOptionsShouldThrow()
        {
            Option[] options = new Option[]
            {
                new Option("a", null, "TestA", "Nothing", false)
            };
            OptionParser parser = new OptionParser(new OptionParser.Configuration(options)
            {
                AllowArgumentsBetweenOptions = false
            });

            string testLine = "-a hola -a";

            Assert.ThrowsException <ParserException>(() => parser.ParseAll(testLine).ToList());
        }
Beispiel #6
0
        public void SingleShortOption()
        {
            Option[] options = new Option[]
            {
                new Option("a", null, "TestA", "Nothing", true)
            };
            OptionParser parser = new OptionParser(new OptionParser.Configuration(options));

            string testLine = "-a 'test'";

            var result = parser.ParseAll(testLine);

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Option == options[0]);
            Assert.AreEqual("test", result.First().Argument);
        }
Beispiel #7
0
        public void MultipleSimpleShortOptions()
        {
            Option[] options = new Option[]
            {
                new Option("a", null, "TestA", "Nothing"),
                new Option("b", null, "TestB", "Nothing")
            };
            OptionParser parser = new OptionParser(new OptionParser.Configuration(options));

            string testLine = "-a -b";

            var result = parser.ParseAll(testLine).ToArray();

            Assert.IsTrue(result.Count() == 2);
            Assert.AreEqual(options[0], result[0].Option);
            Assert.AreEqual(options[1], result[1].Option);
        }
Beispiel #8
0
        public void MultipleLongOptions()
        {
            Option[] options = new Option[]
            {
                new Option("a", "longa", "TestA", "Nothing", true),
                new Option("b", "longb", "TestB", "Nothing", true)
            };
            OptionParser parser = new OptionParser(new OptionParser.Configuration(options));

            string testLine = "--longa 'testa' --longb testb";

            var result = parser.ParseAll(testLine).ToArray();

            Assert.IsTrue(result.Count() == 2);

            Assert.AreEqual(options[0], result[0].Option);
            Assert.AreEqual(options[1], result[1].Option);

            Assert.AreEqual("testa", result[0].Argument);
            Assert.AreEqual("testb", result[1].Argument);
        }