Skip to content

Commit 011b81c

Browse files
kimsey0jonsequitur
authored andcommitted
Add tests for suggestion ordering with and without text to match
1 parent 65e0b68 commit 011b81c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/System.CommandLine.Tests/SuggestionTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.CommandLine.Builder;
66
using System.CommandLine.Invocation;
77
using System.CommandLine.Parsing;
8+
using System.CommandLine.Tests.Utility;
89
using System.IO;
910
using FluentAssertions;
1011
using Xunit;
@@ -112,6 +113,36 @@ public void Command_Suggest_returns_available_subcommands_and_option_aliases_and
112113
.BeEquivalentTo("subcommand", "--option", "command-argument");
113114
}
114115

116+
[Fact]
117+
public void Command_Suggest_without_text_to_match_orders_alphabetically()
118+
{
119+
var command = new Command("command")
120+
{
121+
new Command("andmythirdsubcommand"),
122+
new Command("mysubcommand"),
123+
new Command("andmyothersubcommand"),
124+
};
125+
126+
var suggestions = command.GetSuggestions();
127+
128+
suggestions.Should().BeEquivalentSequenceTo("andmyothersubcommand", "andmythirdsubcommand", "mysubcommand");
129+
}
130+
131+
[Fact]
132+
public void Command_Suggest_with_text_to_match_orders_by_match_position_then_alphabetically()
133+
{
134+
var command = new Command("command")
135+
{
136+
new Command("andmythirdsubcommand"),
137+
new Command("mysubcommand"),
138+
new Command("andmyothersubcommand"),
139+
};
140+
141+
var suggestions = command.GetSuggestions("my");
142+
143+
suggestions.Should().BeEquivalentSequenceTo("mysubcommand", "andmyothersubcommand", "andmythirdsubcommand");
144+
}
145+
115146
[Fact]
116147
public void When_an_option_has_a_default_value_it_will_still_be_suggested()
117148
{

0 commit comments

Comments
 (0)