public function tablesUnitTest::testFormatWidths

8.0.x tablesUnitTest.php public tablesUnitTest::testFormatWidths()
6.x tablesUnitTest.php public tablesUnitTest::testFormatWidths()
7.x tablesUnitTest.php public tablesUnitTest::testFormatWidths()
master tablesUnitTest.php public tablesUnitTest::testFormatWidths()

Tests drush_format_table() at various table widths.

See also

drush_format_table().

File

tests/tablesUnitTest.php, line 66

Namespace

Unish

Class

tablesUnitTest
Unit tests for table formatting.

Code

public function testFormatWidths() {
  // print "\n'" . str_replace("\n", "' . PHP_EOL . '", $output) . "'\n";
  drush_set_context('DRUSH_COLUMNS', 22);
  $output = drush_format_table($this->numbers, FALSE, array(2));
  $expected = ' 1   12       123     ' . PHP_EOL . ' 12  12345    123456  ' . PHP_EOL . ' 34                   ' . PHP_EOL . ' 12  1234567  1234567 ' . PHP_EOL . ' 34  8        89      ' . PHP_EOL . ' 56                   ' . PHP_EOL . ' 7                    ' . PHP_EOL;
  $this->assertEquals($expected, $output);

  $output = drush_format_table($this->numbers, FALSE, array(10));
  $expected = ' 1           12   123 ' . PHP_EOL . ' 1234        123  123 ' . PHP_EOL . '             45   456 ' . PHP_EOL . ' 1234567     123  123 ' . PHP_EOL . '             456  456 ' . PHP_EOL . '             78   789 ' . PHP_EOL;
  $this->assertEquals($expected, $output);

  $output = drush_format_table($this->numbers, FALSE, array(2, 2));
  $expected = ' 1   12  123       ' . PHP_EOL . ' 12  12  123456    ' . PHP_EOL . ' 34  34            ' . PHP_EOL . '     5             ' . PHP_EOL . ' 12  12  123456789 ' . PHP_EOL . ' 34  34            ' . PHP_EOL . ' 56  56            ' . PHP_EOL . ' 7   78            ' . PHP_EOL;
  $this->assertEquals($expected, $output);

  $output = drush_format_table($this->numbers, FALSE, array(4, 4, 4));
  $expected = ' 1     12    123  ' . PHP_EOL . ' 1234  1234  1234 ' . PHP_EOL . '       5     56   ' . PHP_EOL . ' 1234  1234  1234 ' . PHP_EOL . ' 567   5678  5678 ' . PHP_EOL . '             9    ' . PHP_EOL;
  $this->assertEquals($expected, $output);
}