Exemplo n.º 1
0
        public void Parse_AllowSwitchesDoubleHyphenPrefix_OneSwitchCommand()
        {
            var parser = new CommandLineParser();
            parser.RuleSet.AllowSwitches = true;
            parser.RuleSet.Prefixes = CommandPrefixes.DoubleHyphen;

            string[] arguments = new string[1] { "--switch" };
            var commands = parser.Parse(arguments).ToArray();

            Assert.AreEqual(1, commands.Length);

            var command = commands[0];
            Assert.AreEqual("switch", command.Key);
            Assert.IsFalse(command.HasValue);
        }
Exemplo n.º 2
0
        public void Parse_AllowMultipleValuesForwardSlashPrefixColonSeparator_OneCommandWithKeyAndThreeValues()
        {
            var parser = new CommandLineParser();
            parser.RuleSet.AllowMultipleValues = true;
            parser.RuleSet.Prefixes = CommandPrefixes.ForwardSlash;
            parser.RuleSet.Separators = CommandSeparators.Colon;

            string[] arguments = new string[1] { "/key:val1;val2;val3" };
            var commands = parser.Parse(arguments).ToArray();

            Assert.AreEqual(1, commands.Length);

            var command = commands[0];
            Assert.AreEqual("key", command.Key);
            Assert.IsTrue(command.HasValue);

            var commandValue = command.Value as string[];
            Assert.IsNotNull(commandValue);
            Assert.AreEqual(3, commandValue.Length);
            Assert.AreEqual("val1", commandValue[0]);
            Assert.AreEqual("val2", commandValue[1]);
            Assert.AreEqual("val3", commandValue[2]);
        }
Exemplo n.º 3
0
        public void Parse_ForwardSlashPrefixEqualsSeparator_OneCommandWithKeyAndValue()
        {
            var parser = new CommandLineParser();
            parser.RuleSet.Prefixes = CommandPrefixes.ForwardSlash;
            parser.RuleSet.Separators = CommandSeparators.Equals;

            string[] arguments = new string[1] { "/key=value" };
            var commands = parser.Parse(arguments).ToArray();

            Assert.AreEqual(1, commands.Length);

            var command = commands[0];
            Assert.AreEqual("key", command.Key);
            Assert.IsTrue(command.HasValue);

            Assert.AreEqual("value", command.Value);
        }
Exemplo n.º 4
0
        public void Parse_SingleHyphenPrefix_TwoCommands()
        {
            var parser = new CommandLineParser();
            parser.RuleSet.Prefixes = CommandPrefixes.SingleHyphen;

            string[] arguments = new string[2] { "-a", "-b" };
            var commands = parser.Parse(arguments).ToArray();

            Assert.AreEqual(2, commands.Length);

            var command = commands[0];
            Assert.AreEqual("a", command.Key);
            Assert.IsFalse(command.HasValue);

            command = commands[1];
            Assert.AreEqual("b", command.Key);
            Assert.IsFalse(command.HasValue);
        }