Beispiel #1
0
        public void Allow_single_dash_as_option_input_value()
        {
            var options = new SimpleOptions();
            var parser = new Parser();
            var result = parser.ParseArguments(new string[] { "--string", "-" }, options);

            result.Should().BeTrue();
            options.StringValue.Should().Be("-");
        }
Beispiel #2
0
 public void Parse_string_option()
 {
     var options = new SimpleOptions();
     var parser = new CommandLine.Parser();
     var result = parser.ParseArguments(new string[] { "-s", "something" }, options);
     
     result.Should().BeTrue();
     options.StringValue.Should().Be("something");
     Console.WriteLine(options);
 }
Beispiel #3
0
        public void Parse_string_integer_bool_options()
        {
            var options = new SimpleOptions();
            bool result = CommandLine.Parser.Default.ParseArguments(
                    new string[] { "-s", "another string", "-i100", "--switch" }, options);

            result.Should().BeTrue();
            options.StringValue.Should().Be("another string");
            options.IntegerValue.Should().Be(100);
            options.BooleanValue.Should().BeTrue();
            Console.WriteLine(options);
        }
Beispiel #4
0
        public void Parse_strict_bad_input_fails_and_exits()
        {
            var options = new SimpleOptions();
            var testWriter = new StringWriter();

            ReflectionHelper.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
            var parser = new CommandLine.Parser(with => with.HelpWriter = testWriter);
            var result = parser.ParseArgumentsStrict(new string[] {"--bad", "--input"}, options,
                () => Console.WriteLine("fake fail"));

            result.Should().BeFalse();

            var helpText = testWriter.ToString();
            Console.WriteLine(helpText);
            var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            // Did we really produced all help?
            lines.Should().HaveCount(n => n == 8);
            // Verify just significant output
            lines[5].Trim().Should().Be("-s, --string");
            lines[6].Trim().Should().Be("-i");
            lines[7].Trim().Should().Be("--switch");
        }
Beispiel #5
0
 public void Short_option_refuses_equal_token()
 {
     var options = new SimpleOptions();
     var parser = new Parser();
     var result = parser.ParseArguments(new string[] { "-i=10" }, options);
     result.Should().BeFalse();
     Console.WriteLine(options);
 }
Beispiel #6
0
        public void Passing_no_value_to_a_string_type_long_option_fails()
        {
            var options = new SimpleOptions();
            var parser = new Parser();
            var result = parser.ParseArguments(new string[] { "--string" }, options);

            result.Should().BeFalse();
        }
Beispiel #7
0
        public void Parsing_non_existent_short_option_fails_without_throwing_an_exception()
        {
            var options = new SimpleOptions();
            var parser = new Parser();
            var result = parser.ParseArguments(new string[] { "-x" }, options);

            result.Should().BeFalse();
        }
Beispiel #8
0
        public void Parse_negative_integer_value()
        {
            var options = new SimpleOptions();
            var parser = new Parser();
            var result = parser.ParseArguments(new string[] { "-i", "-4096" }, options);

            result.Should().BeTrue();
            options.IntegerValue.Should().Be(-4096);
        }