Skip to content

Commit f96f851

Browse files
committed
clarify tests
1 parent 0b59ad2 commit f96f851

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/System.CommandLine.Tests/ParserTests.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ public void A_root_command_can_be_omitted_from_the_parsed_args()
792792
}
793793

794794
[Fact]
795-
public void A_root_command_can_match_a_full_path_to_an_executable()
795+
public void When_parsing_an_unsplit_string_then_input_a_full_path_to_an_executable_is_matched_by_the_root_command()
796796
{
797797
var command = new RootCommand
798798
{
@@ -802,15 +802,15 @@ public void A_root_command_can_match_a_full_path_to_an_executable()
802802
}
803803
};
804804

805-
ParseResult result1 = command.Parse("inner -x hello");
805+
var result1 = command.Parse("inner -x hello");
806806

807-
ParseResult result2 = command.Parse($"{RootCommand.ExecutablePath} inner -x hello");
807+
var result2 = command.Parse($"{RootCommand.ExecutablePath} inner -x hello");
808808

809809
result1.Diagram().Should().Be(result2.Diagram());
810810
}
811811

812812
[Fact]
813-
public void A_renamed_RootCommand_can_be_omitted_from_the_parsed_args()
813+
public void When_parsing_an_unsplit_string_then_a_renamed_RootCommand_can_be_omitted_from_the_parsed_args()
814814
{
815815
var rootCommand = new RootCommand
816816
{
@@ -828,6 +828,27 @@ public void A_renamed_RootCommand_can_be_omitted_from_the_parsed_args()
828828
result2.RootCommandResult.Command.Should().BeSameAs(result1.RootCommandResult.Command);
829829
result3.RootCommandResult.Command.Should().BeSameAs(result1.RootCommandResult.Command);
830830
}
831+
832+
[Fact]
833+
public void When_parsing_a_string_array_input_then_a_full_path_to_an_executable_is_not_matched_by_the_root_command()
834+
{
835+
var command = new RootCommand
836+
{
837+
new Command("inner")
838+
{
839+
new Option("-x") { Arity = ArgumentArity.ExactlyOne }
840+
}
841+
};
842+
843+
command.Parse(Split("inner -x hello")).Errors.Should().BeEmpty();
844+
845+
command.Parse(Split($"{RootCommand.ExecutablePath} inner -x hello"))
846+
.Errors
847+
.Should()
848+
.ContainSingle(e => e.Message == $"{LocalizationResources.Instance.UnrecognizedCommandOrArgument(RootCommand.ExecutablePath)}");
849+
850+
string[] Split(string value) => CommandLineStringSplitter.Instance.Split(value).ToArray();
851+
}
831852

832853
[Fact]
833854
public void Absolute_unix_style_paths_are_lexed_correctly()

0 commit comments

Comments
 (0)