-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for shell completion helpers
- Loading branch information
Showing
3 changed files
with
88 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.DotNet.Cli.Complete.Tests; | ||
|
||
using Microsoft.DotNet.Cli.Completions.Shells; | ||
using System.CommandLine; | ||
using System.CommandLine.Help; | ||
|
||
public class HelpExtensionsTests | ||
{ | ||
[Fact] | ||
public void HelpOptionOnlyShowsUsefulNames() | ||
{ | ||
new HelpOption().Names().Should().BeEquivalentTo(["--help", "-h"]); | ||
} | ||
|
||
[Fact] | ||
public void OptionNamesListNameThenAliases() | ||
{ | ||
new CliOption<string>("--name", "-n", "--nombre").Names().Should().Equal(["--name", "-n", "--nombre"]); | ||
} | ||
|
||
[Fact] | ||
public void OptionsWithNoAliasesHaveOnlyOneName() | ||
{ | ||
new CliOption<string>("--name").Names().Should().Equal(["--name"]); | ||
} | ||
|
||
[Fact] | ||
public void HeirarchicalOptionsAreFlattened() | ||
{ | ||
var parentCommand = new CliCommand("parent"); | ||
var childCommand = new CliCommand("child"); | ||
parentCommand.Subcommands.Add(childCommand); | ||
parentCommand.Options.Add(new CliOption<string>("--parent-global") { Recursive = true }); | ||
parentCommand.Options.Add(new CliOption<string>("--parent-local") { Recursive = false }); | ||
parentCommand.Options.Add(new CliOption<string>("--parent-global-but-hidden") { Recursive = true, Hidden = true }); | ||
|
||
childCommand.Options.Add(new CliOption<string>("--child-local")); | ||
childCommand.Options.Add(new CliOption<string>("--child-hidden") { Hidden = true }); | ||
|
||
// note: no parent-local or parent-global-but-hidden options, and no locally hidden options | ||
childCommand.HeirarchicalOptions().Select(c => c.Name).Should().Equal(["--parent-global", "--child-local"]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters