Skip to content

Commit 07d7344

Browse files
committed
add tests for CaseInsensitiveEnumValues param
1 parent afd1d5a commit 07d7344

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ private static ParserResult<T> InvokeBuild<T>(string[] arguments)
3030
Enumerable.Empty<ErrorType>());
3131
}
3232

33+
private static ParserResult<T> InvokeBuildEnumValuesCaseIgnore<T>(string[] arguments)
34+
where T : new()
35+
{
36+
return InstanceBuilder.Build(
37+
Maybe.Just<Func<T>>(() => new T()),
38+
(args, optionSpecs) => Tokenizer.ConfigureTokenizer(StringComparer.Ordinal, false, false)(args, optionSpecs),
39+
arguments,
40+
StringComparer.Ordinal,
41+
true,
42+
CultureInfo.InvariantCulture,
43+
Enumerable.Empty<ErrorType>());
44+
}
45+
3346
private static ParserResult<T> InvokeBuildImmutable<T>(string[] arguments)
3447
{
3548
return InstanceBuilder.Build(
@@ -261,6 +274,27 @@ public void Parse_enum_value(string[] arguments, Colors expected)
261274
// Teardown
262275
}
263276

277+
[Theory]
278+
[InlineData(new[] { "--colors", "red" }, Colors.Red)]
279+
[InlineData(new[] { "--colors", "green" }, Colors.Green)]
280+
[InlineData(new[] { "--colors", "blue" }, Colors.Blue)]
281+
[InlineData(new[] { "--colors", "0" }, Colors.Red)]
282+
[InlineData(new[] { "--colors", "1" }, Colors.Green)]
283+
[InlineData(new[] { "--colors", "2" }, Colors.Blue)]
284+
public void Parse_enum_value_ignore_case(string[] arguments, Colors expected)
285+
{
286+
// Fixture setup in attribute
287+
288+
// Exercize system
289+
var result = InvokeBuildEnumValuesCaseIgnore<Simple_Options_With_Enum>(
290+
arguments);
291+
292+
// Verify outcome
293+
expected.ShouldBeEquivalentTo(((Parsed<Simple_Options_With_Enum>)result).Value.Colors);
294+
295+
// Teardown
296+
}
297+
264298
[Fact]
265299
public void Parse_enum_value_with_wrong_index_generates_BadFormatConversionError()
266300
{

0 commit comments

Comments
 (0)