diff --git a/lib/cli/table/Tabular.php b/lib/cli/table/Tabular.php index c7c2a1f..5132e55 100644 --- a/lib/cli/table/Tabular.php +++ b/lib/cli/table/Tabular.php @@ -45,7 +45,6 @@ public function row( array $row ) { foreach ( $rows as $r ) { $output .= implode( "\t", array_values( $r ) ) . PHP_EOL; } - - return trim( $output ); + return rtrim( $output, PHP_EOL ); } } diff --git a/tests/Test_Table.php b/tests/Test_Table.php index 538a4a4..964ec2e 100644 --- a/tests/Test_Table.php +++ b/tests/Test_Table.php @@ -245,4 +245,26 @@ public function test_ascii_pre_colorized_widths() { $this->assertSame( 56, strlen( $out[6] ) ); } + public function test_preserve_trailing_tabs() { + $table = new cli\Table(); + $renderer = new cli\Table\Tabular(); + $table->setRenderer( $renderer ); + + $table->setHeaders( array( 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra' ) ); + + // Add row with missing values at the end + $table->addRow( array( 'date', 'date', 'NO', 'PRI', '', '' ) ); + $table->addRow( array( 'awesome_stuff', 'text', 'YES', '', '', '' ) ); + + $out = $table->getDisplayLines(); + + $expected = [ + "Field\tType\tNull\tKey\tDefault\tExtra", + "date\tdate\tNO\tPRI\t\t", + "awesome_stuff\ttext\tYES\t\t\t", + ]; + + $this->assertSame( $expected, $out, 'Trailing tabs should be preserved in table output.' ); + } + }