Skip to content

Commit

Permalink
Add unit tests for OptionsParseMode
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaeIDietrich committed Sep 12, 2022
1 parent 83426f2 commit 53ef250
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/CommandLine.Tests/Unit/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,5 +1025,32 @@ public void When_HelpWriter_is_null_it_should_not_fire_exception()
//Assert
sut.Settings.MaximumDisplayWidth.Should().BeGreaterThan(1);
}

[Theory]
[InlineData(OptionsParseMode.SingleOrDoubleDash, ParserResultType.Parsed, new[]{ "-s", "value" })]
[InlineData(OptionsParseMode.SingleOrDoubleDash, ParserResultType.Parsed, new[]{ "-shortandlong", "value" })]
[InlineData(OptionsParseMode.SingleOrDoubleDash, ParserResultType.Parsed, new[]{ "--s", "value" })]
[InlineData(OptionsParseMode.SingleOrDoubleDash, ParserResultType.Parsed, new[]{ "--shortandlong", "value" })]
[InlineData(OptionsParseMode.SingleDashOnly, ParserResultType.Parsed, new[]{ "-s", "value" })]
[InlineData(OptionsParseMode.SingleDashOnly, ParserResultType.Parsed, new[]{ "-shortandlong", "value" })]
[InlineData(OptionsParseMode.SingleDashOnly, ParserResultType.NotParsed, new[]{ "--s", "value" })]
[InlineData(OptionsParseMode.SingleDashOnly, ParserResultType.NotParsed, new[]{ "--shortanlong", "value" })]
public void Parse_Options_With_Custom_OptionsParseMode(OptionsParseMode mode, ParserResultType result, string[] arguments)
{
// Arrange
var sut = new Parser(with =>
{
with.OptionsParseMode = mode;
});

// Act
var options = sut.ParseArguments<Simple_Options>(arguments);

// Assert
options.Tag.Should().Be(result);

if (options.Tag == ParserResultType.Parsed)
options.Value.ShortAndLong.Should().Be("value");
}
}
}

0 comments on commit 53ef250

Please sign in to comment.