@@ -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,41 @@ 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
F42D
+ $ 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
+
249
+
201
250
public function testAskWithAutocompleteCallback ()
202
251
{
203
252
if (!$ this ->hasSttyAvailable ()) {
@@ -373,6 +422,21 @@ public function testAskHiddenResponse()
373
422
$ this ->assertEquals ('8AM ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ this ->getInputStream ("8AM \n" )), $ this ->createOutputInterface (), $ question ));
374
423
}
375
424
425
+ public function testAskHiddenResponseTrimmed ()
426
+ {
427
+ if ('\\' === \DIRECTORY_SEPARATOR ) {
428
+ $ this ->markTestSkipped ('This test is not supported on Windows ' );
429
+ }
430
+
431
+ $ dialog = new QuestionHelper ();
432
+
433
+ $ question = new Question ('What time is it? ' );
434
+ $ question ->setHidden (true );
435
+ $ question ->setTrimmable (false );
436
+
437
+ $ this ->assertEquals (' 8AM ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ this ->getInputStream (' 8AM ' )), $ this ->createOutputInterface (), $ question ));
438
+ }
439
+
376
440
/**
377
441
* @dataProvider getAskConfirmationData
378
442
*/
0 commit comments