8000 [Console] Add more autocomplete tests · symfony/symfony@9fbfe1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fbfe1c

Browse files
committed
[Console] Add more autocomplete tests
1 parent 68648b2 commit 9fbfe1c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
306306
$remainingCharacters = substr($ret, strlen(trim($this->mostRecentlyEnteredValue($fullChoice))));
307307
$output->write($remainingCharacters);
308308
$fullChoice .= $remainingCharacters;
309-
$i = \strlen($ret);
309+
$i = strlen($fullChoice);
310310
}
311311

312312
if ("\n" === $c) {

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,38 @@ public function testTraversableAutocomplete()
10181018
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
10191019
}
10201020

1021+
public function testTraversableMultiselectAutocomplete()
1022+
{
1023+
// Test cases:
1024+
// 1) default; 2) Tab single; 3) Traverse and tab multiple; 4) Backspace and traverse multiple; 5) Backspace all
1025+
1026+
// <NEWLINE>
1027+
// F<TAB><NEWLINE>
1028+
// A<3x UP ARROW><TAB>,F<TAB><NEWLINE>
1029+
// F00<BACKSPACE><BACKSPACE>o<TAB>,A<DOWN ARROW>,<SPACE>SecurityBundle<NEWLINE>
1030+
// Acme<TAB> ,<SPACE>As<TAB><29x BACKSPACE>S<TAB><NEWLINE>
1031+
$inputStream = $this->getInputStream("\nF\t\nA\033[A\033[A\033[A\t,F\t\nF00\177\177o\t,A\033[B\t, SecurityBundle\nAcme\t, As\t\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177S\t\n");
1032+
1033+
$dialog = new QuestionHelper();
1034+
$helperSet = new HelperSet([new FormatterHelper()]);
1035+
$dialog->setHelperSet($helperSet);
1036+
1037+
$question = new ChoiceQuestion(
1038+
'Please select a bundle (defaults to AcmeDemoBundle and AsseticBundle)',
1039+
['AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle'],
1040+
'0,1'
1041+
);
1042+
1043+
// This tests that autocomplete works for all multiselect choices entered by the user
1044+
$question->setMultiselect(true);
1045+
1046+
$this->assertEquals(['AcmeDemoBundle', 'AsseticBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
1047+
$this->assertEquals(['FooBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
1048+
$this->assertEquals(['AsseticBundle', 'FooBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
1049+
$this->assertEquals(['FooBundle', 'AsseticBundle', 'SecurityBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
1050+
$this->assertEquals(['SecurityBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
1051+
}
1052+
10211053
protected function getInputStream($input)
10221054
{
10231055
$stream = fopen('php://memory', 'r+', false);

0 commit comments

Comments
 (0)
0