Skip to content

Commit 3fde60a

Browse files
committed
fix: negative $times for str_repeat, tests
1 parent 0039a85 commit 3fde60a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Output/Writer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,8 @@ public function justify(string $first, ?string $second = null, array $options =
321321
'sep' => $options['sep'] ?? '.',
322322
];
323323

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

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

338338
return $this->eol();
339339
}

tests/Output/ProgressBarTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function test_progress_bar()
3434
}
3535
}
3636

37-
$this->assertBufferContains('===========================================> 100%');
37+
$this->assertBufferContains('==========================================> 100%');
3838
$this->assertBufferContains('10 x label');
3939

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

54-
$this->assertBufferContains('###########################################~ 100%');
54+
$this->assertBufferContains('##########################################~ 100%');
5555
$this->assertBufferContains('#1 label');
5656

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

76-
$this->assertBufferContains('===========================================> 100%');
76+
$this->assertBufferContains('==========================================> 100%');
7777
$this->assertBufferContains('c: 3');
7878
$this->assertNotNull((new Terminal)->height());
7979

0 commit comments

Comments
 (0)