Пример #1
0
        public void TestDoNotIgnoreCase()
        {
            OptionTable T = new OptionTable(InfoTable);


            string[]          MyArgs = new string[] { "-a", "-joo" };
            InputArgumentList AL     = T.ParseArgs(MyArgs, out int MAI, out int MAC);

            Assert.IsTrue(!AL.HasArg(OPT_ID.OPT_A));
            Assert.IsTrue(!AL.HasArg(OPT_ID.OPT_B));
        }
Пример #2
0
        public void TestSlurpJoinedEmpty()
        {
            OptionTable T = new OptionTable(InfoTable);


            string[]          MyArgs = new string[] { "-A", "-slurpjoined" };
            InputArgumentList AL     = T.ParseArgs(MyArgs, out int MAI, out int MAC);

            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_A));
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_SlurpJoined));
            Assert.IsTrue(AL.GetAllArgValues(OPT_ID.OPT_SlurpJoined).Count == 0U);
        }
Пример #3
0
        public void TestParseWithFlagExclusions()
        {
            OptionTable T = new OptionTable(InfoTable);


            // Exclude flag3 to avoid parsing as OPT_ID.OPT_SLASH_C.
            InputArgumentList AL = T.ParseArgs(Args, out int MAI, out int MAC, /*FlagsToInclude=*/ 0, /*FlagsToExclude=*/ (int)OptionFlags.OptFlag3);

            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_A));
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_C));
            Assert.IsTrue(!AL.HasArg(OPT_ID.OPT_SLASH_C));

            // Exclude flag1 to avoid parsing as OPT_ID.OPT_C.
            AL = T.ParseArgs(Args, out MAI, out MAC, /*FlagsToInclude=*/ 0, /*FlagsToExclude=*/ (int)OptionFlags.OptFlag1);
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_B));
            Assert.IsTrue(!AL.HasArg(OPT_ID.OPT_C));
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_SLASH_C));

            string[] NewArgs = new string[] { "/C", "foo", "--C=bar" };
            AL = T.ParseArgs(NewArgs, out MAI, out MAC);
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_SLASH_C));
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_C));
            Assert.IsTrue("foo" == AL.GetLastArgValue(OPT_ID.OPT_SLASH_C));
            Assert.IsTrue("bar" == AL.GetLastArgValue(OPT_ID.OPT_C));
        }
Пример #4
0
        public void TestSlurpJoinedButSeparate()
        {
            OptionTable T = new OptionTable(InfoTable);


            string[]          MyArgs = new string[] { "-A", "-slurpjoined", "foo", "bar", "baz" };
            InputArgumentList AL     = T.ParseArgs(MyArgs, out int MAI, out int MAC);

            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_A));
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_SlurpJoined));
            Assert.IsTrue(3U == AL.GetAllArgValues(OPT_ID.OPT_SlurpJoined).Count);
            Assert.IsTrue("foo" == AL.GetAllArgValues(OPT_ID.OPT_SlurpJoined)[0]);
            Assert.IsTrue("bar" == AL.GetAllArgValues(OPT_ID.OPT_SlurpJoined)[1]);
            Assert.IsTrue("baz" == AL.GetAllArgValues(OPT_ID.OPT_SlurpJoined)[2]);
        }
Пример #5
0
        public void TestSlurp()
        {
            OptionTable T = new OptionTable(InfoTable);


            string[]          MyArgs = new string[] { "-A", "-slurp", "-B", "--", "foo" };
            InputArgumentList AL     = T.ParseArgs(MyArgs, out int MAI, out int MAC);

            Assert.IsTrue(AL.Size() == 2U);
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_A));
            Assert.IsTrue(!AL.HasArg(OPT_ID.OPT_B));
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_Slurp));
            Assert.IsTrue(3U == AL.GetAllArgValues(OPT_ID.OPT_Slurp).Count);
            Assert.IsTrue("-B" == AL.GetAllArgValues(OPT_ID.OPT_Slurp)[0]);
            Assert.IsTrue("--" == AL.GetAllArgValues(OPT_ID.OPT_Slurp)[1]);
            Assert.IsTrue("foo" == AL.GetAllArgValues(OPT_ID.OPT_Slurp)[2]);
        }
Пример #6
0
        public void TestParseAliasInGroup()
        {
            OptionTable T = new OptionTable(InfoTable);


            string[]          MyArgs = new string[] { "-I" };
            InputArgumentList AL     = T.ParseArgs(MyArgs, out int MAI, out int MAC);

            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_H));
        }
Пример #7
0
        public void TestAliasArgs()
        {
            OptionTable T = new OptionTable(InfoTable);


            string[]          MyArgs = new string[] { "-J", "-Joo" };
            InputArgumentList AL     = T.ParseArgs(MyArgs, out int MAI, out int MAC);

            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_B));
            Assert.IsTrue("foo" == AL.GetAllArgValues(OPT_ID.OPT_B)[0]);
            Assert.IsTrue("bar" == AL.GetAllArgValues(OPT_ID.OPT_B)[1]);
        }
Пример #8
0
        public void TestOptionParsing()
        {
            OptionTable T = new OptionTable(InfoTable);

            int FlagsToInclude = 0;
            int FlagsToExclude = 0;

            InputArgumentList al = T.ParseArgs(Args, out int missingArgIndex, out int missingArgCount, FlagsToInclude, FlagsToExclude);

            // Check they all exist.
            Assert.IsTrue(al.HasArg(OPT_ID.OPT_A));
            Assert.IsTrue(al.HasArg(OPT_ID.OPT_B));
            Assert.IsTrue(al.HasArg(OPT_ID.OPT_C));
            Assert.IsTrue(al.HasArg(OPT_ID.OPT_D));
            Assert.IsTrue(al.HasArg(OPT_ID.OPT_E));
            Assert.IsTrue(al.HasArg(OPT_ID.OPT_F));
            Assert.IsTrue(al.HasArg(OPT_ID.OPT_G));

            // Check the values.

            Assert.IsTrue("hi" == al.GetLastArgValue(OPT_ID.OPT_B));
            Assert.IsTrue("bye" == al.GetLastArgValue(OPT_ID.OPT_C));
            Assert.IsTrue("adena" == al.GetLastArgValue(OPT_ID.OPT_D));
            List <string> Es = al.GetAllArgValues(OPT_ID.OPT_E);

            Assert.IsTrue("apple" == Es[0]);
            Assert.IsTrue("bloom" == Es[1]);
            Assert.IsTrue("42" == al.GetLastArgValue(OPT_ID.OPT_F));
            List <string> Gs = al.GetAllArgValues(OPT_ID.OPT_G);

            Assert.IsTrue("chuu" == Gs[0]);
            Assert.IsTrue("2" == Gs[1]);

            // Check the help text.
            StringBuilder RSO = new StringBuilder();

            T.PrintHelp(RSO, "test", "title!");
            string Help = RSO.ToString();

            Assert.IsTrue(Help.Length != Help.IndexOf("-A", StringComparison.Ordinal));

            // Test aliases.
            var Cs = al.Filtered(OPT_ID.OPT_C);

            Assert.IsTrue(Cs.First() != Cs.Last());
            Assert.IsTrue("desu" == Cs.First().GetValue());
            List <string> ASL = new List <string>();

            Cs.First().Render(al, ASL);
            Assert.IsTrue(2u == ASL.Count);
            Assert.IsTrue("-C" == ASL[0]);
            Assert.IsTrue("desu" == ASL[1]);
        }
Пример #9
0
        public void TestFlagAliasToJoined()
        {
            OptionTable T = new OptionTable(InfoTable);

            // Check that a flag alias provides an empty argument to a joined option.
            string[]          MyArgs = new string[] { "-K" };
            InputArgumentList AL     = T.ParseArgs(MyArgs, out int MAI, out int MAC);

            Assert.IsTrue(AL.Size() == 1U);
            Assert.IsTrue(AL.HasArg(OPT_ID.OPT_B));

            var allArgs = AL.GetAllArgValues(OPT_ID.OPT_B);

            Assert.IsTrue(1U == allArgs.Count);
            Assert.IsTrue("" == AL.GetAllArgValues(OPT_ID.OPT_B)[0]);
        }