Exemple #1
0
        public void should_get_free_value_continuously_for_specified_command()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginCommand("command", string.Empty)
                                .ConfigFreeValue(true)
                                .EndCommand()
                                .Build();

            ArgsParsingResult result = parser.Parse(new[] { "command", "free-value1", "free-value2" });

            result.AssertSuccess();
            Assert.Equal(new [] { "free-value1", "free-value2" }, result.GetUndefinedFreeValues());
        }
Exemple #2
0
        public void should_get_free_value_for_default_command()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginDefaultCommand()
                                .ConfigFreeValue(true)
                                .EndCommand()
                                .Build();

            ArgsParsingResult result = parser.Parse(new[] { "free-value" });

            result.AssertSuccess();
            Assert.Equal(new [] { "free-value" }, result.GetUndefinedFreeValues());
        }
Exemple #3
0
        public void should_throw_if_getting_undefined_free_values_in_a_failure_result()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginDefaultCommand()
                                .ConfigFreeValue(true)
                                .AddOptionWithValue("option", 'o', string.Empty, true)
                                .EndCommand()
                                .Build();

            ArgsParsingResult result = parser.Parse(new [] { "value" });

            Assert.False(result.IsSuccess);

            Assert.Throws <InvalidOperationException>(() => result.GetUndefinedFreeValues());
        }
Exemple #4
0
        public void should_get_as_free_value_after_one_free_value()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginCommand("command", string.Empty)
                                .ConfigFreeValue(true)
                                .AddFlagOption("flag", 'f', string.Empty)
                                .EndCommand()
                                .Build();

            ArgsParsingResult result = parser.Parse(new [] { "command", "-a", "-f" });

            result.AssertSuccess();
            Assert.Equal(new [] { "-a", "-f" }, result.GetUndefinedFreeValues());
            Assert.False(result.GetFlagValue("--flag"));
        }
Exemple #5
0
        public void should_capture_multiple_free_values_with_undefined_ones()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginCommand("command", string.Empty)
                                .AddFreeValue("name", "description")
                                .AddFreeValue("age", "description")
                                .EndCommand()
                                .Build();

            ArgsParsingResult result = parser.Parse(
                new[] { "command", "name_value", "age_value", "undefined_value1", "undefined_value2" });

            result.AssertSuccess();
            Assert.Equal("name_value", result.GetFreeRawValue("name"));
            Assert.Equal("age_value", result.GetFreeRawValue("age"));
            Assert.Equal(new object[] { "undefined_value1", "undefined_value2" }, result.GetUndefinedFreeValues());
        }