コード例 #1
0
        public void ArgParse_Parse_Success()
        {
            ArgParse  argParse  = new ArgParse();
            Option    option    = new Option("-a", "--add", "Add an option", true, true);
            Option    option2   = new Option("-d", "--delete", "Delete an option", false, true);
            OptionSet optionSet = new OptionSet("Two parameters");

            optionSet.Add(option);
            optionSet.Add(option2);
            argParse.Add(optionSet);
            OptionSet optionSet2 = new OptionSet("One parameter");
            Option    option3    = new Option("-v", "--version", "Version of the application", true, false);

            optionSet2.Add(option3);
            argParse.Add(optionSet2);

            string[] args = { "-a", "anOption" };
            argParse.Parse(args);
            OptionSet activeOptionSet = argParse.GetActiveOptionSet();

            if (activeOptionSet != null)
            {
                Assert.AreEqual("Two parameters", activeOptionSet.Name);
            }
            else
            {
                Assert.Fail();
            }
        }
コード例 #2
0
        public void ArgParse_Parse_onearg_Fail()
        {
            ArgParse  argParse  = new ArgParse();
            Option    option    = new Option("-a", "--add", "Add an option", true, true);
            Option    option2   = new Option("-d", "--delete", "Delete an option", false, true);
            OptionSet optionSet = new OptionSet("Two parameters");

            optionSet.Add(option);
            optionSet.Add(option2);
            argParse.Add(optionSet);
            OptionSet optionSet2 = new OptionSet("One parameter");
            Option    option3    = new Option("-v", "--version", "Version of the application", true, false);

            optionSet2.Add(option3);
            argParse.Add(optionSet2);

            string[] args2 = { "-d", "anOption" };
            Assert.Throws <ArgumentException>(() => argParse.Parse(args2));
        }
コード例 #3
0
        public void ArgParse_TwoOptionSetTwoOptions_Add_Success()
        {
            ArgParse  argParse  = new ArgParse();
            Option    option    = new Option("-a", "--add", "Add an option", true, true);
            Option    option2   = new Option("-d", "--delete", "Delete an option", false, true);
            OptionSet optionSet = new OptionSet("Two parameters");

            optionSet.Add(option);
            optionSet.Add(option2);
            argParse.Add(optionSet);
            OptionSet optionSet2 = new OptionSet("One parameter");
            Option    option3    = new Option("-v", "--version", "Version of the application", true, false);

            optionSet2.Add(option3);
            argParse.Add(optionSet2);

            Assert.AreEqual("Usage:\nTwo parameters:\n\t-a\t--add Value\t\t" +
                            "Add an option\n\t-d\t--delete Value\t\t[Optional] Delete an option\n" +
                            "One parameter:\n\t-v\t--version\t\tVersion of the application\n", argParse.Usage());
        }
コード例 #4
0
        public void ArgParse_OneOptionSet_Add_Success()
        {
            ArgParse  argParse  = new ArgParse();
            Option    option    = new Option("-a", "--add", "Add an option", true, true);
            OptionSet optionSet = new OptionSet("Single parameter");

            optionSet.Add(option);
            argParse.Add(optionSet);

            Assert.AreEqual("Usage:\nSingle parameter:\n\t-a\t--add Value\t\tAdd an option\n", argParse.Usage());
        }
コード例 #5
0
        public void ArgParse_OneOptionSetTwoOptions_Add_Success()
        {
            ArgParse  argParse  = new ArgParse();
            Option    option    = new Option("-a", "--add", "Add an option", true, true);
            Option    option2   = new Option("-d", "--delete", "Delete an option", false, true);
            OptionSet optionSet = new OptionSet("Two parameters");

            optionSet.Add(option);
            optionSet.Add(option2);
            argParse.Add(optionSet);

            Assert.AreEqual("Usage:\nTwo parameters:\n\t-a\t--add Value\t\tAdd an option" +
                            "\n\t-d\t--delete Value\t\t[Optional] Delete an option\n", argParse.Usage());
        }