88using System . CommandLine . Tests . Utility ;
99using System . IO ;
1010using FluentAssertions ;
11+
12+ using Microsoft . Extensions . Logging ;
13+
1114using Xunit ;
1215using Xunit . Abstractions ;
1316
@@ -29,9 +32,9 @@ public void Option_Suggest_returns_argument_suggestions_if_configured()
2932 {
3033 Argument = new Argument
3134 {
32- Arity = ArgumentArity . ExactlyOne
35+ Arity = ArgumentArity . ExactlyOne ,
36+ SuggestionSources = { "one" , "two" , "three" }
3337 }
34- . WithSuggestions ( "one" , "two" , "three" )
3538 } ;
3639
3740 var suggestions = option . GetSuggestions ( ) ;
@@ -102,9 +105,9 @@ public void Command_Suggest_returns_available_subcommands_and_option_aliases_and
102105 new Option ( "--option" , "option" ) ,
103106 new Argument
104107 {
105- Arity = ArgumentArity . OneOrMore
108+ Arity = ArgumentArity . OneOrMore ,
109+ SuggestionSources = { "command-argument" }
106110 }
107- . WithSuggestions ( "command-argument" )
108111 } ;
109112
110113 var suggestions = command . GetSuggestions ( ) ;
@@ -505,9 +508,9 @@ public void Suggestions_can_be_provided_in_the_absence_of_validation()
505508 {
506509 Argument = new Argument
507510 {
508- Arity = ArgumentArity . ExactlyOne
511+ Arity = ArgumentArity . ExactlyOne ,
512+ SuggestionSources = { "vegetable" , "mineral" , "animal" }
509513 }
510- . WithSuggestions ( "vegetable" , "mineral" , "animal" )
511514 }
512515 } ;
513516
@@ -529,14 +532,9 @@ public void Command_argument_suggestions_can_be_provided_using_a_delegate()
529532 {
530533 new Argument
531534 {
532- Arity = ArgumentArity . ExactlyOne
535+ Arity = ArgumentArity . ExactlyOne ,
536+ SuggestionSources = { _ => new [ ] { "vegetable" , "mineral" , "animal" } }
533537 }
534- . WithSuggestionSource ( _ => new [ ]
535- {
536- "vegetable" ,
537- "mineral" ,
538- "animal"
539- } )
540538 }
541539 } ;
542540
@@ -551,13 +549,13 @@ public void Option_argument_suggestions_can_be_provided_using_a_delegate()
551549 {
552550 var command = new Command ( "the-command" )
553551 {
554- new Option < string > ( "-x" )
555- . WithSuggestionSource ( _ => new [ ]
552+ new Option < string > ( "-x" )
553+ {
554+ Argument = new Argument < string > ( )
556555 {
557- "vegetable" ,
558- "mineral" ,
559- "animal"
560- } )
556+ SuggestionSources = { _ => new [ ] { "vegetable" , "mineral" , "animal" } }
557+ }
558+ }
561559 } ;
562560
563561 var parseResult = command . Parse ( "the-command -x m" ) ;
@@ -997,6 +995,40 @@ public void When_there_are_multiple_arguments_then_suggestions_are_only_offered_
997995 {
998996 Assert . True ( false , "Test testname is not written yet." ) ;
999997 }
998+
999+ [ Fact ]
1000+ public void Enum_suggestions_can_be_configured_with_list_clear ( )
1001+ {
1002+ var argument = new Argument < LogLevel ? > ( ) ;
1003+ argument . SuggestionSources . Clear ( ) ;
1004+ argument . SuggestionSources . Add ( new [ ] { "q" , "quiet" , "m" , "minimal" , "n" , "normal" , "d" , "detailed" , "diag" , "diagnostic" } ) ;
1005+ var command = new Command ( "the-command" )
1006+ {
1007+ argument
1008+ } ;
1009+
1010+ var suggestions = command . Parse ( "the-command d" )
1011+ . GetSuggestions ( ) ;
1012+
1013+ suggestions . Should ( ) . BeEquivalentTo ( "d" , "detailed" , "diag" , "diagnostic" ) ;
1014+ }
1015+
1016+ [ Fact ]
1017+ public void Enum_suggestions_can_be_configured_without_list_clear ( )
1018+ {
1019+ var command = new Command ( "the-command" )
1020+ {
1021+ new Argument < LogLevel ? > ( )
1022+ {
1023+ SuggestionSources = { "q" , "quiet" , "m" , "minimal" , "n" , "normal" , "d" , "detailed" , "diag" , "diagnostic" }
1024+ }
1025+ } ;
1026+
1027+ var suggestions = command . Parse ( "the-command d" )
1028+ . GetSuggestions ( ) ;
1029+
1030+ suggestions . Should ( ) . BeEquivalentTo ( "d" , "Debug" , "detailed" , "diag" , "diagnostic" ) ;
1031+ }
10001032 }
10011033 }
10021034}
0 commit comments