Beispiel #1
0
        public void Single_dash_as_a_value(string[] args, int countExcepted, string first, string last)
        {
            //Arrange
            //Act
            var result = GetoptTokenizer.Tokenize(args, name => NameLookupResult.OtherOptionFound);
            var tokens = result.SucceededWith().ToList();

            //Assert
            tokens.Should().NotBeNull();
            tokens.Count.Should().Be(countExcepted);
            tokens.First().Text.Should().Be(first);
            tokens.Last().Text.Should().Be(last);
        }
Beispiel #2
0
 private static Result <IEnumerable <Token>, Error> Tokenize(
     IEnumerable <string> arguments,
     IEnumerable <OptionSpecification> optionSpecs,
     ParserSettings settings)
 {
     return(settings.GetoptMode
         ? GetoptTokenizer.ConfigureTokenizer(
                settings.NameComparer,
                settings.IgnoreUnknownArguments,
                settings.EnableDashDash,
                settings.PosixlyCorrect)(arguments, optionSpecs)
         : Tokenizer.ConfigureTokenizer(
                settings.NameComparer,
                settings.IgnoreUnknownArguments,
                settings.EnableDashDash)(arguments, optionSpecs));
 }
Beispiel #3
0
        public void Should_properly_parse_option_with_equals_in_value()
        {
            /**
             * This is how the arg. would look in `static void Main(string[] args)`
             * if passed from the command-line and the option-value wrapped in quotes.
             * Ex.) ./app --connectionString="Server=localhost;Data Source..."
             */
            var args = new[] { "--connectionString=Server=localhost;Data Source=(LocalDB)\v12.0;Initial Catalog=temp;" };

            var result = GetoptTokenizer.Tokenize(args, name => NameLookupResult.OtherOptionFound);

            var tokens = result.SucceededWith();

            Assert.NotNull(tokens);
            Assert.Equal(2, tokens.Count());
            Assert.Equal("connectionString", tokens.First().Text);
            Assert.Equal("Server=localhost;Data Source=(LocalDB)\v12.0;Initial Catalog=temp;", tokens.Last().Text);
        }
Beispiel #4
0
        public void Should_return_error_if_option_format_with_equals_is_not_correct()
        {
            var args = new[] { "--option1 = fail", "--option2= succeed" };

            var result = GetoptTokenizer.Tokenize(args, name => NameLookupResult.OtherOptionFound);

            var errors = result.SuccessMessages();

            Assert.NotNull(errors);
            Assert.Equal(1, errors.Count());
            Assert.Equal(ErrorType.BadFormatTokenError, errors.First().Tag);

            var tokens = result.SucceededWith();

            Assert.NotNull(tokens);
            Assert.Equal(2, tokens.Count());
            Assert.Equal(TokenType.Name, tokens.First().Tag);
            Assert.Equal(TokenType.Value, tokens.Last().Tag);
            Assert.Equal("option2", tokens.First().Text);
            Assert.Equal(" succeed", tokens.Last().Text);
        }
Beispiel #5
0
        public void Explode_scalar_with_separator_in_even_args_input_returns_sequence()
        {
            // Fixture setup
            var expectedTokens = new[] { Token.Name("x"), Token.Name("string-seq"),
                                         Token.Value("aaa"), Token.Value("bb"), Token.Value("cccc"), Token.Name("switch") };
            var specs = new[] { new OptionSpecification(string.Empty, "string-seq",
                                                        false, string.Empty, Maybe.Nothing <int>(), Maybe.Nothing <int>(), ',', null, string.Empty, string.Empty, new List <string>(), typeof(IEnumerable <string>), TargetType.Sequence, string.Empty) };

            // Exercize system
            var result =
                GetoptTokenizer.ExplodeOptionList(
                    Result.Succeed(
                        Enumerable.Empty <Token>().Concat(new[] { Token.Name("x"),
                                                                  Token.Name("string-seq"), Token.Value("aaa,bb,cccc"), Token.Name("switch") }),
                        Enumerable.Empty <Error>()),
                    optionName => NameLookup.HavingSeparator(optionName, specs, StringComparer.Ordinal));

            // Verify outcome
            ((Ok <IEnumerable <Token>, Error>)result).Success.Should().BeEquivalentTo(expectedTokens);

            // Teardown
        }