@@ -87,8 +87,8 @@ private List<String> toCandidateDisplayText(List<Candidate> candidates) {
8787 }
8888
8989 @ ParameterizedTest
90- @ MethodSource ("completeData " )
91- void testComplete (List <String > words , List <String > expectedValues ) {
90+ @ MethodSource ("completeWithCompletionData " )
91+ void testCompleteWithCompletion (List <String > words , List <String > expectedValues ) {
9292 // given
9393 when (command .getOptions ())
9494 .thenReturn (List .of (new CommandOption .Builder ().longName ("first" ).shortName ('f' ).build (),
@@ -107,51 +107,85 @@ void testComplete(List<String> words, List<String> expectedValues) {
107107 assertEquals (expectedValues , toCandidateNames (candidates ));
108108 }
109109
110- static Stream <Arguments > completeData () {
110+ static Stream <Arguments > completeWithCompletionData () {
111+ return completeData ("" );
112+ }
113+
114+ @ ParameterizedTest
115+ @ MethodSource ("completeWithoutCompletionData" )
116+ void testCompleteWithoutCompletion (List <String > words , List <String > expectedValues ) {
117+ // given
118+ when (command .getName ()).thenReturn ("hello" );
119+ when (command .getOptions ())
120+ .thenReturn (List .of (new CommandOption .Builder ().longName ("first" ).shortName ('f' ).completion (false ).build (),
121+ new CommandOption .Builder ().longName ("last" ).shortName ('l' ).completion (false ).build ()));
122+
123+ List <Candidate > candidates = new ArrayList <>();
124+ ParsedLine line = mock (ParsedLine .class );
125+ when (line .words ()).thenReturn (words );
126+ when (line .word ()).thenReturn (words .get (words .size () - 1 ));
127+ when (line .line ()).thenReturn (String .join (" " , words ));
128+
129+ // when
130+ completer .complete (mock (LineReader .class ), line , candidates );
131+
132+ // then
133+ assertEquals (expectedValues , toCandidateNames (candidates ));
134+ }
135+
136+ static Stream <Arguments > completeWithoutCompletionData () {
137+ return completeData ("=" );
138+ }
139+
140+ static Stream <Arguments > completeData (String sep ) {
111141 return Stream .of (Arguments .of (List .of ("" ), List .of ("hello" )), Arguments .of (List .of ("he" ), List .of ("hello" )),
112142 Arguments .of (List .of ("he" , "" ), List .of ()), Arguments .of (List .of ("hello" ), List .of ("hello" )),
113143
114- Arguments .of (List .of ("hello" , "" ), List .of ("--first" , "--last" , "-f" , "-l" )),
115- Arguments .of (List .of ("hello" , "--" ), List .of ("--first" , "--last" , "-f" , "-l" )),
116- Arguments .of (List .of ("hello" , "-" ), List .of ("--first" , "--last" , "-f" , "-l" )),
117- Arguments .of (List .of ("hello" , "--fi" ), List .of ("--first" , "--last" , "-f" , "-l" )),
118- Arguments .of (List .of ("hello" , "--la" ), List .of ("--first" , "--last" , "-f" , "-l" )),
144+ Arguments .of (List .of ("hello" , "" ), List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
145+ Arguments .of (List .of ("hello" , "--" ), List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
146+ Arguments .of (List .of ("hello" , "-" ), List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
147+ Arguments .of (List .of ("hello" , "--fi" ),
148+ List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
149+ Arguments .of (List .of ("hello" , "--la" ),
150+ List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
119151
120- Arguments .of (List .of ("hello" , "-f" ), List .of ("--first" , "--last" , "-f" , "-l" )),
152+ Arguments .of (List .of ("hello" , "-f" ), List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
121153 Arguments .of (List .of ("hello" , "-f=" ), List .of ("-f=Mary" , "-f=Paul" , "-f=Peter" )),
122154 Arguments .of (List .of ("hello" , "-f=Pe" ), List .of ("-f=Mary" , "-f=Paul" , "-f=Peter" )),
123- Arguments .of (List .of ("hello" , "-f=Pe" , "" ), List .of ("--last" , "-l" )),
155+ Arguments .of (List .of ("hello" , "-f=Pe" , "" ), List .of ("--last" + sep , "-l" + sep )),
124156
125- Arguments .of (List .of ("hello" , "--first" ), List .of ("--first" , "--last" , "-f" , "-l" )),
157+ Arguments .of (List .of ("hello" , "--first" ),
158+ List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
126159 Arguments .of (List .of ("hello" , "--first=" ), List .of ("--first=Mary" , "--first=Paul" , "--first=Peter" )),
127160 Arguments .of (List .of ("hello" , "--first=Pe" ), List .of ("--first=Mary" , "--first=Paul" , "--first=Peter" )),
128- Arguments .of (List .of ("hello" , "--first=Pe" , "" ), List .of ("--last" , "-l" )),
161+ Arguments .of (List .of ("hello" , "--first=Pe" , "" ), List .of ("--last" + sep , "-l" + sep )),
129162
130163 Arguments .of (List .of ("hello" , "-f" , "" ), List .of ("Mary" , "Paul" , "Peter" )),
131164 Arguments .of (List .of ("hello" , "--first" , "" ), List .of ("Mary" , "Paul" , "Peter" )),
132165
133166 Arguments .of (List .of ("hello" , "-f" , "Pe" ), List .of ("Mary" , "Paul" , "Peter" )),
134- Arguments .of (List .of ("hello" , "-f" , "Pe" , "" ), List .of ("--last" , "-l" )),
167+ Arguments .of (List .of ("hello" , "-f" , "Pe" , "" ), List .of ("--last" + sep , "-l" + sep )),
135168 Arguments .of (List .of ("hello" , "--first" , "Pe" ), List .of ("Mary" , "Paul" , "Peter" )),
136- Arguments .of (List .of ("hello" , "--first" , "Pe" , "" ), List .of ("--last" , "-l" )),
169+ Arguments .of (List .of ("hello" , "--first" , "Pe" , "" ), List .of ("--last" + sep , "-l" + sep )),
137170
138- Arguments .of (List .of ("hello" , "-l" ), List .of ("--first" , "--last" , "-f" , "-l" )),
171+ Arguments .of (List .of ("hello" , "-l" ), List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
139172 Arguments .of (List .of ("hello" , "-l=" ), List .of ("-l=Chan" , "-l=Noris" )),
140173 Arguments .of (List .of ("hello" , "-l=No" ), List .of ("-l=Chan" , "-l=Noris" )),
141- Arguments .of (List .of ("hello" , "-l=No" , "" ), List .of ("--first" , "-f" )),
174+ Arguments .of (List .of ("hello" , "-l=No" , "" ), List .of ("--first" + sep , "-f" + sep )),
142175
143- Arguments .of (List .of ("hello" , "--last" ), List .of ("--first" , "--last" , "-f" , "-l" )),
176+ Arguments .of (List .of ("hello" , "--last" ),
177+ List .of ("--first" + sep , "--last" + sep , "-f" + sep , "-l" + sep )),
144178 Arguments .of (List .of ("hello" , "--last=" ), List .of ("--last=Chan" , "--last=Noris" )),
145179 Arguments .of (List .of ("hello" , "--last=No" ), List .of ("--last=Chan" , "--last=Noris" )),
146- Arguments .of (List .of ("hello" , "--last=No" , "" ), List .of ("--first" , "-f" )),
180+ Arguments .of (List .of ("hello" , "--last=No" , "" ), List .of ("--first" + sep , "-f" + sep )),
147181
148182 Arguments .of (List .of ("hello" , "-l" , "" ), List .of ("Chan" , "Noris" )),
149183 Arguments .of (List .of ("hello" , "--last" , "" ), List .of ("Chan" , "Noris" )),
150184
151185 Arguments .of (List .of ("hello" , "-l" , "No" ), List .of ("Chan" , "Noris" )),
152- Arguments .of (List .of ("hello" , "-l" , "No" , "" ), List .of ("--first" , "-f" )),
186+ Arguments .of (List .of ("hello" , "-l" , "No" , "" ), List .of ("--first" + sep , "-f" + sep )),
153187 Arguments .of (List .of ("hello" , "--last" , "No" ), List .of ("Chan" , "Noris" )),
154- Arguments .of (List .of ("hello" , "--last" , "No" , "" ), List .of ("--first" , "-f" )),
188+ Arguments .of (List .of ("hello" , "--last" , "No" , "" ), List .of ("--first" + sep , "-f" + sep )),
155189
156190 Arguments .of (List .of ("hello" , "--first" , "Paul" , "--last" , "Noris" , "" ), List .of ()),
157191 Arguments .of (List .of ("hello" , "--first" , "Paul" , "-l" , "Noris" , "" ), List .of ()),
0 commit comments