public static void UnParsing_instance_with_no_values_and_dashdash_enabled_returns_command_line_without_dash_dash()
 {
     var options = new Simple_Options_With_Values();
     new Parser((setting) => setting.EnableDashDash = true)
         .FormatCommandLine(options)
         .ShouldBeEquivalentTo("");
 }
 public static void UnParsing_instance_with_dash_in_value_and_dashdash_enabled_returns_command_line_with_value_prefixed_with_dash_dash()
 {
     var options = new Simple_Options_With_Values { StringSequence = new List<string> { "-something", "with", "dash" } };
     new Parser((setting) => setting.EnableDashDash = true)
         .FormatCommandLine(options)
         .ShouldBeEquivalentTo("-- -something with dash");
 }
        public void Double_dash_force_subsequent_arguments_as_values()
        {
            // Fixture setup
            var expectedResult = new Simple_Options_With_Values
                {
                    StringValue = "str1",
                    LongValue = 10L,
                    StringSequence = new[] { "-a", "--bee", "-c" },
                    IntValue = 20
                };
            var arguments = new[] { "--stringvalue", "str1", "--", "10", "-a", "--bee", "-c", "20" };

            // Exercize system
            var result = InstanceBuilder.Build(
                Maybe.Just<Func<Simple_Options_With_Values>>(() => new Simple_Options_With_Values()),
                (a, optionSpecs) =>
                    Tokenizer.PreprocessDashDash(a,
                        args => Tokenizer.Tokenize(args, name => NameLookup.Contains(name, optionSpecs, StringComparer.Ordinal))),
                arguments,
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture,
                Enumerable.Empty<ErrorType>());

            // Verify outcome
            expectedResult.ShouldBeEquivalentTo(((Parsed<Simple_Options_With_Values>)result).Value);

            // Teardown
        }
        public void Parse_values_partitioned_between_sequence_and_scalar()
        {
            // Fixture setup
            var expectedResult = new Simple_Options_With_Values
                {
                    StringValue = string.Empty,
                    LongValue = 10L,
                    StringSequence = new[] { "a", "b", "c" },
                    IntValue = 20
                };

            // Exercize system
            var result = InstanceBuilder.Build(
                Maybe.Just<Func<Simple_Options_With_Values>>(() => new Simple_Options_With_Values()),
                new[] { "10", "a", "b", "c", "20" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture,
                Enumerable.Empty<ErrorType>());

            // Verify outcome
            expectedResult.ShouldBeEquivalentTo(((Parsed<Simple_Options_With_Values>)result).Value);

            // Teardown
        }
Example #5
0
        public void Parse_options_with_double_dash()
        {
            // Fixture setup
            var expectedOptions = new Simple_Options_With_Values
                                  {
                                      StringValue = "astring",
                                      LongValue = 20L,
                                      StringSequence = new[] { "--aaa", "-b", "--ccc" },
                                      IntValue = 30
                                  };
            var sut = new Parser(with => with.EnableDashDash = true);

            // Exercize system
            var result =
                sut.ParseArguments<Simple_Options_With_Values>(
                    new[] { "--stringvalue", "astring", "--", "20", "--aaa", "-b", "--ccc", "30" });

            // Verify outcome
            ((Parsed<Simple_Options_With_Values>)result).Value.ShouldBeEquivalentTo(expectedOptions);
            // Teardown
        }
 public static void UnParsing_instance_with_dash_in_value_and_dashdash_disabled_returns_command_line_with_value()
 {
     var options = new Simple_Options_With_Values { StringSequence = new List<string> { "-something", "with", "dash" } };
     new Parser()
         .FormatCommandLine(options)
         .ShouldBeEquivalentTo("-something with dash");
 }