From 48b84a397e5ad245c0c14f7b47a0663e5af50514 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 31 Dec 2015 16:01:51 -0800 Subject: [PATCH 1/2] Use a more impossible placeholder pattern in `Colors::colorize()` This prevents true percent + space combinations from losing the space. --- lib/cli/Colors.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli/Colors.php b/lib/cli/Colors.php index 306f595..51083aa 100644 --- a/lib/cli/Colors.php +++ b/lib/cli/Colors.php @@ -127,13 +127,13 @@ static public function colorize($string, $colored = null) { return $return; } - $string = str_replace('%%', '% ', $string); + $string = str_replace('%%', '%¾', $string); foreach (self::getColors() as $key => $value) { $string = str_replace($key, self::color($value), $string); } - $string = str_replace('% ', '%', $string); + $string = str_replace('%¾', '%', $string); self::cacheString($passed, $string, $colored); return $string; From 99aefded5d5aeb247f05f8f93b50c7ba64e710dd Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 31 Dec 2015 16:10:29 -0800 Subject: [PATCH 2/2] Add test case for 48b84a397e5ad245c0c14f7b47a0663e5af50514 --- tests/test-table-ascii.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test-table-ascii.php b/tests/test-table-ascii.php index 6058146..d7b7610 100644 --- a/tests/test-table-ascii.php +++ b/tests/test-table-ascii.php @@ -146,6 +146,35 @@ public function testTableWithPercentCharacters() { | % at start | at end % | in % middle | +------------+----------+-------------+ +OUT; + $this->assertInOutEquals(array($headers, $rows), $output); + } + + /** + * Test that a % is appropriately padded in the table + */ + public function testTablePaddingWithPercentCharacters() { + $headers = array( 'ID', 'post_title', 'post_name' ); + $rows = array( + array( + 3, + '10%', + '' + ), + array( + 1, + 'Hello world!', + 'hello-world' + ), + ); + $output = <<<'OUT' ++----+--------------+-------------+ +| ID | post_title | post_name | ++----+--------------+-------------+ +| 3 | 10% | | +| 1 | Hello world! | hello-world | ++----+--------------+-------------+ + OUT; $this->assertInOutEquals(array($headers, $rows), $output); }