From 6473d441a913cb997123b59ff2dbe3d1cf9e11ba Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Fri, 28 Jun 2024 14:45:31 +0700 Subject: [PATCH] Test convert CompletionInput into string --- Completion/CompletionInput.php | 2 +- Tests/Completion/CompletionInputTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Completion/CompletionInput.php b/Completion/CompletionInput.php index 368b94507..2f631bcd8 100644 --- a/Completion/CompletionInput.php +++ b/Completion/CompletionInput.php @@ -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 { diff --git a/Tests/Completion/CompletionInputTest.php b/Tests/Completion/CompletionInputTest.php index d98da682c..65708d3ec 100644 --- a/Tests/Completion/CompletionInputTest.php +++ b/Tests/Completion/CompletionInputTest.php @@ -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); + } }