@@ -165,6 +165,20 @@ public function testAsk()
165
165
$ this ->assertEquals ('What time is it? ' , stream_get_contents ($ output ->getStream ()));
166
166
}
167
167
168
+ public function testAskNonTrimmed ()
169
+ {
170
+ $ dialog = new QuestionHelper ();
171
+
172
+ $ inputStream = $ this ->getInputStream (' 8AM ' );
173
+
174
+ $ question = new Question ('What time is it? ' , '2PM ' );
175
+ $ question ->setTrimmable (false );
176
+ $ this ->assertEquals (' 8AM ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ output = $ this ->createOutputInterface (), $ question ));
177
+
178
+ rewind ($ output ->getStream ());
179
+ $ this ->assertEquals ('What time is it? ' , stream_get_contents ($ output ->getStream ()));
180
+ }
181
+
168
182
public function testAskWithAutocomplete ()
169
183
{
170
184
if (!$ this ->hasSttyAvailable ()) {
@@ -198,6 +212,40 @@ public function testAskWithAutocomplete()
198
212
$ this ->assertEquals ('FooBundle ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
199
213
}
200
214
215
+ public function testAskWithAutocompleteTrimmable ()
216
+ {
217
+ if (!$ this ->hasSttyAvailable ()) {
218
+ $ this ->markTestSkipped ('`stty` is required to test autocomplete functionality ' );
219
+ }
220
+
221
+ // Acm<NEWLINE>
222
+ // Ac<BACKSPACE><BACKSPACE>s<TAB>Test<NEWLINE>
223
+ // <NEWLINE>
224
+ // <UP ARROW><UP ARROW><NEWLINE>
225
+ // <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB>Test<NEWLINE>
226
+ // <DOWN ARROW><NEWLINE>
227
+ // S<BACKSPACE><BACKSPACE><DOWN ARROW><DOWN ARROW><NEWLINE>
228
+ // F00<BACKSPACE><BACKSPACE>oo<TAB><NEWLINE>
229
+ $ inputStream = $ this ->getInputStream ("Acm \nAc \177\177s \tTest \n\n\033[A \033[A \n\033[A \033[A \033[A \033[A \033[A \tTest \n\033[B \nS \177\177\033[B \033[B \nF00 \177\177oo \t\n" );
230
+
231
+ $ dialog = new QuestionHelper ();
232
+ $ helperSet = new HelperSet ([new FormatterHelper ()]);
233
+ $ dialog ->setHelperSet ($ helperSet );
234
+
235
+ $ question = new Question ('Please select a bundle ' , 'FrameworkBundle ' );
236
+ $ question ->setAutocompleterValues (['AcmeDemoBundle ' , 'AsseticBundle ' , ' SecurityBundle ' , 'FooBundle ' ]);
237
+ $ question ->setTrimmable (false );
238
+
239
+ $ this ->assertEquals ('AcmeDemoBundle ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
240
+ $ this ->assertEquals ('AsseticBundleTest ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
241
+ $ this ->assertEquals ('FrameworkBundle ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
242
+ $ this ->assertEquals (' SecurityBundle ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
243
+ $ this ->assertEquals ('FooBundleTest ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
244
+ $ this ->assertEquals ('AcmeDemoBundle ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
245
+ $ this ->assertEquals ('AsseticBundle ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
246
+ $ this ->assertEquals ('FooBundle ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ inputStream ), $ this ->createOutputInterface (), $ question ));
247
+ }
248
+
201
249
public function testAskWithAutocompleteCallback ()
202
250
{
203
251
if (!$ this ->hasSttyAvailable ()) {
@@ -373,6 +421,21 @@ public function testAskHiddenResponse()
373
421
$ this ->assertEquals ('8AM ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ this ->getInputStream ("8AM \n" )), $ this ->createOutputInterface (), $ question ));
374
422
}
375
423
424
+ public function testAskHiddenResponseTrimmed ()
425
+ {
426
+ if ('\\' === \DIRECTORY_SEPARATOR ) {
427
+ $ this ->markTestSkipped ('This test is not supported on Windows ' );
428
+ }
429
+
430
+ $ dialog = new QuestionHelper ();
431
+
432
+ $ question = new Question ('What time is it? ' );
433
+ $ question ->setHidden (true );
434
+ $ question ->setTrimmable (false );
435
+
436
+ $ this ->assertEquals (' 8AM ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ this ->getInputStream (' 8AM ' )), $ this ->createOutputInterface (), $ question ));
437
+ }
438
+
376
439
/**
377
440
* @dataProvider getAskConfirmationData
378
441
*/
0 commit comments