-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97e22f0
commit 15c8020
Showing
5 changed files
with
41 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
<?php | ||
namespace Cognesy\Utils\Tests\Utils; | ||
|
||
use Cognesy\Instructor\Utils\Cli\Color; | ||
use Cognesy\Instructor\Utils\Cli\Console; | ||
|
||
it('displays single string column correctly', function () { | ||
$output = Console::columns(['Sample text'], 80); | ||
expect($output)->toBe('Sample text '); | ||
expect($output)->toBe('Sample text' . Color::RESET . ' '); | ||
}); | ||
|
||
it('aligns single column text to the left by default', function () { | ||
$output = Console::columns([[-1, 'Left aligned', STR_PAD_LEFT]], 80); | ||
expect($output)->toBe(str_pad('Left aligned', 80, ' ', STR_PAD_LEFT)); | ||
})->skip(); | ||
expect($output)->toBe( | ||
str_pad('Left aligned', 80, ' ', STR_PAD_LEFT) | ||
. Color::RESET . ' ' | ||
); | ||
}); | ||
|
||
it('aligns single column text to the right', function () { | ||
$output = Console::columns([[-1, 'Right aligned', STR_PAD_RIGHT]], 80); | ||
expect($output)->toBe(str_pad('Right aligned', 80, ' ', STR_PAD_RIGHT)); | ||
})->skip(); | ||
expect($output)->toBe( | ||
str_pad('Right aligned', 80, ' ', STR_PAD_RIGHT) | ||
. Color::RESET . ' ' | ||
); | ||
}); | ||
|
||
it('truncates and appends ellipsis to long text based on maxWidth', function () { | ||
$longText = str_repeat('A', 100); | ||
$output = Console::columns([[-1, $longText]], 80); | ||
$expected = str_pad(substr($longText, 0, 79) . '… ', 80); | ||
$expected = str_pad(substr($longText, 0, 79) . '…' . Color::RESET . ' ', 80); | ||
expect($output)->toBe($expected); | ||
}); | ||
|
||
it('handles mixed array of strings and column specifications', function () { | ||
$output = Console::columns(['Static text', [-1, 'Dynamic text', STR_PAD_RIGHT]], 80); | ||
expect($output)->toBe('Static text Dynamic text '); | ||
expect($output)->toBe( | ||
'Static text' . Color::RESET . ' ' | ||
. 'Dynamic text' | ||
. ' ' . Color::RESET . ' '); | ||
}); | ||
|
||
it('ensures minWidth of 80 if maxWidth is less', function () { | ||
$output = Console::columns([[-1, 'Min width enforced', STR_PAD_RIGHT]], 10); | ||
expect(strlen($output))->toBeGreaterThanOrEqual(80); | ||
})->skip(); | ||
expect(strlen($output))->toBe(80 + strlen(Color::RESET . ' ')); | ||
}); |