@@ -11,15 +11,13 @@ namespace System.CommandLine.Tests
11
11
public class DirectiveTests
12
12
{
13
13
[ Fact ]
14
- public void Directives_should_not_be_considered_as_unmatched_tokens_when_they_are_enabled ( )
14
+ public void Directives_should_be_considered_as_unmatched_tokens_when_they_are_not_matched ( )
15
15
{
16
- RootCommand root = new ( ) { new Option < bool > ( "-y" ) } ;
17
- CommandLineBuilder builder = new ( root ) ;
18
- builder . Directives . Add ( new ( "some" ) ) ;
16
+ Directive directive = new ( "parse" ) ;
19
17
20
- var result = root . Parse ( $ "{ RootCommand . ExecutableName } [parse ] -y", builder . Build ( ) ) ;
18
+ ParseResult result = Parse ( new Option < bool > ( "-y" ) , directive , $ "{ RootCommand . ExecutableName } [nonExisting ] -y") ;
21
19
22
- result . UnmatchedTokens . Should ( ) . BeEmpty ( ) ;
20
+ result . UnmatchedTokens . Should ( ) . ContainSingle ( "[nonExisting]" ) ;
23
21
}
24
22
25
23
[ Fact ]
@@ -99,14 +97,19 @@ public void Directives_must_have_a_non_empty_key(string directive)
99
97
}
100
98
101
99
[ Theory ]
102
- [ InlineData ( "[par se]" ) ]
103
- [ InlineData ( "[ parse]" ) ]
104
- [ InlineData ( "[parse ]" ) ]
105
- public void Directives_cannot_contain_spaces ( string value )
100
+ [ InlineData ( "[par se]" , "[par" , "se]" ) ]
101
+ [ InlineData ( "[ parse]" , "[" , "parse]" ) ]
102
+ [ InlineData ( "[parse ]" , "[parse" , "]" ) ]
103
+ public void Directives_cannot_contain_spaces ( string value , string firstUnmatchedToken , string secondUnmatchedToken )
106
104
{
107
105
Action create = ( ) => new Directive ( value ) ;
108
-
109
106
create . Should ( ) . Throw < ArgumentException > ( ) ;
107
+
108
+ Directive directive = new ( "parse" ) ;
109
+ ParseResult result = Parse ( new Option < bool > ( "-y" ) , directive , $ "{ value } -y") ;
110
+ result . FindResultFor ( directive ) . Should ( ) . BeNull ( ) ;
111
+
112
+ result . UnmatchedTokens . Should ( ) . BeEquivalentTo ( firstUnmatchedToken , secondUnmatchedToken ) ;
110
113
}
111
114
112
115
[ Fact ]
@@ -119,24 +122,6 @@ public void When_a_directive_is_specified_more_than_once_then_its_values_are_agg
119
122
result . FindResultFor ( directive ) . Values . Should ( ) . BeEquivalentTo ( "one" , "two" ) ;
120
123
}
121
124
122
- [ Fact ]
123
- public void When_directives_are_not_enabled_they_are_treated_as_regular_tokens ( )
124
- {
125
- var config = new CommandLineConfiguration (
126
- new RootCommand
127
- {
128
- new Argument < List < string > > ( )
129
- } ) ;
130
-
131
- var result = config . RootCommand . Parse ( "[hello]" , config ) ;
132
-
133
- result . CommandResult
134
- . Tokens
135
- . Select ( t => t . Value )
136
- . Should ( )
137
- . BeEquivalentTo ( "[hello]" ) ;
138
- }
139
-
140
125
private static ParseResult Parse ( Option option , Directive directive , string commandLine )
141
126
{
142
127
RootCommand root = new ( ) { option } ;
0 commit comments