8000 [Console] Don't go past exact matches when autocompleting · symfony/symfony@e18fcbc · GitHub
[go: up one dir, main page]

Skip to content

Commit e18fcbc

Browse files
[Console] Don't go past exact matches when autocompleting
1 parent 16edba5 commit e18fcbc

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
284284

285285
foreach ($autocomplete as $value) {
286286
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
287-
if (0 === strpos($value, $ret) && $i !== strlen($value)) {
287+
if (0 === strpos($value, $ret)) {
288288
$matches[$numMatches++] = $value;
289289
}
290290
}

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,31 @@ public function testAskWithAutocompleteWithNonSequentialKeys()
160160
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
161161
}
162162

163+
public function testAskWithAutocompleteWithExactMatch()
164+
{
165+
if (!$this->hasSttyAvailable()) {
166+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
167+
}
168+
169+
// <UP ARROW><UP ARROW><NEWLINE><DOWN ARROW><DOWN ARROW><NEWLINE>
170+
$inputStream = $this->getInputStream("b\n");
171+
172+
$possibleChoices = array(
173+
'a' => 'berlin',
174+
'b' => 'copenhagen',
175+
'c' => 'amsterdam',
176+
);
177+
178+
$dialog = new QuestionHelper();
179+
$dialog->setInputStream($inputStream);
180+
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
181+
182+
$question = new ChoiceQuestion('Please select a city', $possibleChoices);
183+
$question->setMaxAttempts(1);
184+
185+
$this->assertEquals('b', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
186+
}
187+
163188
public function testAutocompleteWithTrailingBackslash()
164189
{
165190
if (!$this->hasSttyAvailable()) {

0 commit comments

Comments
 (0)
0