Skip to content

Commit

Permalink
Test convert CompletionInput into string
Browse files Browse the repository at this point in the history
  • Loading branch information
seriquynh committed Jun 28, 2024
1 parent aa73115 commit 6473d44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Completion/CompletionInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function fromString(string $inputStr, int $currentIndex): self
* Create an input based on an COMP_WORDS token list.
*
* @param string[] $tokens the set of split tokens (e.g. COMP_WORDS or argv)
* @param $currentIndex the index of the cursor (e.g. COMP_CWORD)
* @param int $currentIndex the index of the cursor (e.g. COMP_CWORD)
*/
public static function fromTokens(array $tokens, int $currentIndex): self
{
Expand Down
15 changes: 15 additions & 0 deletions Tests/Completion/CompletionInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,19 @@ public static function provideFromStringData()
yield ['bin/console cache:clear "multi word string"', ['bin/console', 'cache:clear', '"multi word string"']];
yield ['bin/console cache:clear \'multi word string\'', ['bin/console', 'cache:clear', '\'multi word string\'']];
}

public function testToString()
{
$input = CompletionInput::fromTokens(['foo', 'bar', 'baz'], 0);
$this->assertSame('foo| bar baz', (string) $input);

$input = CompletionInput::fromTokens(['foo', 'bar', 'baz'], 1);
$this->assertSame('foo bar| baz', (string) $input);

$input = CompletionInput::fromTokens(['foo', 'bar', 'baz'], 2);
$this->assertSame('foo bar baz|', (string) $input);

$input = CompletionInput::fromTokens(['foo', 'bar', 'baz'], 11);
$this->assertSame('foo bar baz |', (string) $input);
}
}

0 comments on commit 6473d44

Please sign in to comment.