Skip to content

Commit 40fa9eb

Browse files
committed
refactor: Simplify readability of the code
1 parent 5c2315c commit 40fa9eb

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/Options/FormatsOption.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ public FormatsOption()
1818
Validators.Add(static result =>
1919
{
2020
var values = result.Tokens
21-
.Select(token => token.Value)
22-
.Where(value => !string.IsNullOrWhiteSpace(value))
23-
.ToArray();
21+
.Select(token => token.Value);
2422
foreach(var value in values)
2523
{
2624
if(!_allowedValues.Contains(value))

tests/PowerUtils.BenchmarkDotnet.Reporter.Tests/Options/FormatOptionTests.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void When_Format_Is_Valid_Shouldnt_Have_Validation_Error(string format)
6565
[InlineData("invalid-format")]
6666
[InlineData("csv")]
6767
[InlineData("html")]
68-
public void When_Format_Is_Invalid_Should_Have_Validation_Error(string? format)
68+
public void When_Format_Is_Invalid_Should_Have_Validation_Error(string format)
6969
{
7070
// Arrange
7171
var command = "compare";
@@ -85,4 +85,29 @@ public void When_Format_Is_Invalid_Should_Have_Validation_Error(string? format)
8585
firstOptionResult?.Errors.Count().ShouldBe(1);
8686
firstOptionResult?.Errors.ShouldContain(e => e.Message == $"Invalid format '{format}'. Allowed values: console, markdown, json, hit-txt");
8787
}
88+
89+
[Theory]
90+
[InlineData("")]
91+
[InlineData(" ")]
92+
[InlineData(null)]
93+
public void When_Format_Isnt_Defined_Should_Have_Validation_Error(string? format)
94+
{
95+
// Arrange
96+
var command = "compare";
97+
var option = "--format";
98+
99+
var toolCommands = new ToolCommands(_provider);
100+
var compareCommand = toolCommands.Subcommands.Single(c => c.Name == command);
101+
var formatsOption = compareCommand.Options.Single(o => o.Name == option);
102+
var validation = formatsOption.Validators.Single();
103+
104+
105+
// Act
106+
var parseResult = toolCommands.Parse($"{command} {option} {format}");
107+
var firstOptionResult = parseResult.GetResult(formatsOption);
108+
109+
// Assert
110+
firstOptionResult?.Errors.Count().ShouldBe(1);
111+
firstOptionResult?.Errors.ShouldContain(e => e.Message == "Required argument missing for option: '--format'.");
112+
}
88113
}

0 commit comments

Comments
 (0)