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); }
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); }
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); }