Skip to content

Commit 53ef250

Browse files
Add unit tests for OptionsParseMode
1 parent 83426f2 commit 53ef250

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/CommandLine.Tests/Unit/ParserTests.cs

+27
Original file line numberDiff line numberDiff line change
@@ -1025,5 +1025,32 @@ public void When_HelpWriter_is_null_it_should_not_fire_exception()
10251025
//Assert
10261026
sut.Settings.MaximumDisplayWidth.Should().BeGreaterThan(1);
10271027
}
1028+
1029+
[Theory]
1030+
[InlineData(OptionsParseMode.SingleOrDoubleDash, ParserResultType.Parsed, new[]{ "-s", "value" })]
1031+
[InlineData(OptionsParseMode.SingleOrDoubleDash, ParserResultType.Parsed, new[]{ "-shortandlong", "value" })]
1032+
[InlineData(OptionsParseMode.SingleOrDoubleDash, ParserResultType.Parsed, new[]{ "--s", "value" })]
1033+
[InlineData(OptionsParseMode.SingleOrDoubleDash, ParserResultType.Parsed, new[]{ "--shortandlong", "value" })]
1034+
[InlineData(OptionsParseMode.SingleDashOnly, ParserResultType.Parsed, new[]{ "-s", "value" })]
1035+
[InlineData(OptionsParseMode.SingleDashOnly, ParserResultType.Parsed, new[]{ "-shortandlong", "value" })]
1036+
[InlineData(OptionsParseMode.SingleDashOnly, ParserResultType.NotParsed, new[]{ "--s", "value" })]
1037+
[InlineData(OptionsParseMode.SingleDashOnly, ParserResultType.NotParsed, new[]{ "--shortanlong", "value" })]
1038+
public void Parse_Options_With_Custom_OptionsParseMode(OptionsParseMode mode, ParserResultType result, string[] arguments)
1039+
{
1040+
// Arrange
1041+
var sut = new Parser(with =>
1042+
{
1043+
with.OptionsParseMode = mode;
1044+
});
1045+
1046+
// Act
1047+
var options = sut.ParseArguments<Simple_Options>(arguments);
1048+
1049+
// Assert
1050+
options.Tag.Should().Be(result);
1051+
1052+
if (options.Tag == ParserResultType.Parsed)
1053+
options.Value.ShortAndLong.Should().Be("value");
1054+
}
10281055
}
10291056
}

0 commit comments

Comments
 (0)