Skip to content

Commit

Permalink
fix: negative $times for str_repeat, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Mar 28, 2024
1 parent 0039a85 commit 3fde60a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Output/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ public function justify(string $first, ?string $second = null, array $options =
'sep' => $options['sep'] ?? '.',
];

$second = (string) $second;

$dashWidth = $this->terminal->width() - (strlen($first) + strlen($second));
$second = (string) $second;
$dashWidth = $this->terminal->width() - (strlen($first) + strlen($second));
// remove left and right margins because we're going to add 1 space on each side (after/before the text).
// if we don't have a second element, we just remove the left margin
$dashWidth -= $second === '' ? 1 : 2;
Expand All @@ -333,7 +332,8 @@ public function justify(string $first, ?string $second = null, array $options =
$second = $this->colorizer->line($second, $options['second']);
}

$this->write($first . ' ' . str_repeat((string) $options['sep'], $dashWidth) . ' ' . $second);
$sep = $dashWidth >= 0 ? str_repeat((string) $options['sep'], $dashWidth) : '';
$this->write($first . ' ' . $sep . ' ' . $second);

return $this->eol();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Output/ProgressBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function test_progress_bar()
}
}

$this->assertBufferContains('===========================================> 100%');
$this->assertBufferContains('==========================================> 100%');
$this->assertBufferContains('10 x label');

$this->expectException(UnexpectedValueException::class);
Expand All @@ -51,7 +51,7 @@ public function test_progress_bar_option()
$progress->advance(1, $label);
}

$this->assertBufferContains('###########################################~ 100%');
$this->assertBufferContains('##########################################~ 100%');
$this->assertBufferContains('#1 label');

$this->expectException(UnexpectedValueException::class);
Expand All @@ -73,7 +73,7 @@ public function getIterator(): Traversable
}
}, fn ($v, $k) => "$k: $v");

$this->assertBufferContains('===========================================> 100%');
$this->assertBufferContains('==========================================> 100%');
$this->assertBufferContains('c: 3');
$this->assertNotNull((new Terminal)->height());

Expand Down

0 comments on commit 3fde60a

Please sign in to comment.