123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace League\CLImate\Tests;
- class PaddingTest extends TestBase
- {
- /** @test */
- public function it_can_wrap_a_line()
- {
- $max_width = $this->util->width();
- $padding = $this->cli->padding();
- $content = str_repeat('a', $max_width * 2);
- $content = substr($content, 0, ($max_width * 2) - 5);
- $this->output->shouldReceive('sameLine');
- $this->shouldWrite("\e[m" . substr($content, 0, $max_width) . "\e[0m");
- $this->shouldWrite("\e[m" . substr($content, $max_width) . ".....\e[0m");
- $this->shouldWrite("\e[m result\e[0m");
- $padding->label($content)->result('result');
- }
- /** @test */
- public function it_can_chain()
- {
- $padding = $this->cli->padding(10);
- $this->output->shouldReceive('sameLine');
- $this->shouldWrite("\e[mPad me....\e[0m");
- $this->shouldWrite("\e[m extra\e[0m");
- $padding->label('Pad me')->result('extra');
- }
- /** @test */
- public function it_can_pad_with_multiple_characters()
- {
- $padding = $this->cli->padding(10)->char('.-');
- $this->output->shouldReceive('sameLine');
- $this->shouldWrite("\e[mPad me.-.-\e[0m");
- $this->shouldWrite("\e[m extra\e[0m");
- $padding->label('Pad me')->result('extra');
- }
- /** @test */
- public function it_can_pad_with_multiple_characters_odd()
- {
- $padding = $this->cli->padding(10)->char('.-');
- $this->output->shouldReceive('sameLine');
- $this->shouldWrite("\e[mPad odd.-.\e[0m");
- $this->shouldWrite("\e[m extra\e[0m");
- $padding->label('Pad odd')->result('extra');
- }
- /** @test */
- public function it_can_pad_with_multibyte_characters()
- {
- $padding = $this->cli->padding(10);
- $this->output->shouldReceive("sameLine");
- $this->shouldWrite("\e[mЛорем.....\e[0m");
- $this->shouldWrite("\e[m END\e[0m");
- $padding->label("Лорем")->result("END");
- }
- /** @test */
- public function it_can_wrap_a_multibyte_line()
- {
- $max_width = $this->util->width();
- $padding = $this->cli->padding();
- $content = "Лорем" . str_repeat('a', $max_width * 2);
- $content = mb_substr($content, 0, ($max_width * 2) - 5);
- $this->output->shouldReceive('sameLine');
- $this->shouldWrite("\e[m" . mb_substr($content, 0, $max_width) . "\e[0m");
- $this->shouldWrite("\e[m" . mb_substr($content, $max_width) . ".....\e[0m");
- $this->shouldWrite("\e[m result\e[0m");
- $padding->label($content)->result('result');
- }
- /** @test */
- public function it_can_add_newline_without_result()
- {
- $padding = $this->cli->padding(10);
- $this->output->shouldReceive('sameLine');
- $this->shouldWrite('Pad me....');
- $this->shouldWrite('');
- $padding->label('Pad me')->br();
- }
- }
|