First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,35 @@
--TEST--
Header and data as associative arrays.
--FILE--
<?php
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$headers = array(
'one' => 'foo',
'two' => 'bar'
);
$data = array(
array(
'x' => 'baz',
)
);
$table = new Console_Table();
$table->setHeaders($headers);
$table->addData($data);
echo $table->getTable();
?>
--EXPECT--
+-----+-----+
| foo | bar |
+-----+-----+
| baz | |
+-----+-----+

View file

@ -0,0 +1,24 @@
--TEST--
Border: default ASCII mode
--FILE--
<?php
error_reporting(E_ALL | E_NOTICE);
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, CONSOLE_TABLE_BORDER_ASCII);
$table->setHeaders(array('City', 'Mayor'));
$table->addRow(array('Leipzig', 'Major Tom'));
$table->addRow(array('New York', 'Towerhouse'));
echo $table->getTable();
?>
--EXPECT--
+----------+------------+
| City | Mayor |
+----------+------------+
| Leipzig | Major Tom |
| New York | Towerhouse |
+----------+------------+

View file

@ -0,0 +1,27 @@
--TEST--
Border: new custom mode
--FILE--
<?php
error_reporting(E_ALL | E_NOTICE);
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table(
CONSOLE_TABLE_ALIGN_LEFT,
array('horizontal' => '=', 'vertical' => ':', 'intersection' => '*')
);
$table->setHeaders(array('City', 'Mayor'));
$table->addRow(array('Leipzig', 'Major Tom'));
$table->addRow(array('New York', 'Towerhouse'));
echo $table->getTable();
?>
--EXPECT--
*==========*============*
: City : Mayor :
*==========*============*
: Leipzig : Major Tom :
: New York : Towerhouse :
*==========*============*

View file

@ -0,0 +1,27 @@
--TEST--
Border: new custom mode, alternative style
--FILE--
<?php
error_reporting(E_ALL | E_NOTICE);
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table(
CONSOLE_TABLE_ALIGN_LEFT,
array('horizontal' => '=', 'vertical' => '', 'intersection' => '')
);
$table->setHeaders(array('City', 'Mayor'));
$table->addRow(array('Leipzig', 'Major Tom'));
$table->addRow(array('New York', 'Towerhouse'));
echo $table->getTable();
?>
--EXPECT--
======================
City Mayor
======================
Leipzig Major Tom
New York Towerhouse
======================

View file

@ -0,0 +1,68 @@
--TEST--
Border: disable it
--FILE--
<?php
error_reporting(E_ALL | E_NOTICE);
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table();
$table->setHeaders(array('City', 'Mayor'));
$table->addRow(array('Leipzig', 'Major Tom'));
$table->addRow(array('New York', 'Towerhouse'));
$table->setBorderVisibility(
array(
'left' => false,
'right' => false,
)
);
echo "Horizontal borders only:\n";
echo $table->getTable() . "\n";
$table->setBorderVisibility(
array(
'top' => false,
'right' => false,
'bottom' => false,
'left' => false,
'inner' => false,
)
);
echo "No borders:\n";
echo $table->getTable() . "\n";
$table->setBorderVisibility(
array(
'top' => false,
'right' => true,
'bottom' => false,
'left' => true,
'inner' => true,
)
);
echo "Vertical and inner only:\n";
echo $table->getTable() . "\n";
?>
--EXPECT--
Horizontal borders only:
---------+-----------
City | Mayor
---------+-----------
Leipzig | Major Tom
New York | Towerhouse
---------+-----------
No borders:
City | Mayor
Leipzig | Major Tom
New York | Towerhouse
Vertical and inner only:
| City | Mayor |
+----------+------------+
| Leipzig | Major Tom |
| New York | Towerhouse |

View file

@ -0,0 +1,24 @@
--TEST--
Border: custom border character
--FILE--
<?php
error_reporting(E_ALL | E_NOTICE);
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, '.');
$table->setHeaders(array('City', 'Mayor'));
$table->addRow(array('Leipzig', 'Major Tom'));
$table->addRow(array('New York', 'Towerhouse'));
echo $table->getTable();
?>
--EXPECT--
.........................
. City . Mayor .
.........................
. Leipzig . Major Tom .
. New York . Towerhouse .
.........................

View file

@ -0,0 +1,21 @@
--TEST--
Border: empty character
--FILE--
<?php
error_reporting(E_ALL | E_NOTICE);
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, '');
$table->setHeaders(array('City', 'Mayor'));
$table->addRow(array('Leipzig', 'Major Tom'));
$table->addRow(array('New York', 'Towerhouse'));
echo $table->getTable() . "\n";
?>
--EXPECT--
City Mayor
Leipzig Major Tom
New York Towerhouse

View file

@ -0,0 +1,23 @@
--TEST--
Bug #20181: setAlign() on non-zero column
--FILE--
<?php
error_reporting(E_ALL | E_NOTICE);
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table();
$table->setAlign(1, CONSOLE_TABLE_ALIGN_RIGHT);
$table->setHeaders(array('f', 'bar'));
$table->addRow(array('baz', 'b'));
echo $table->getTable();
?>
--EXPECT--
+-----+-----+
| f | bar |
+-----+-----+
| baz | b |
+-----+-----+

View file

@ -0,0 +1,28 @@
--TEST--
Data with ANSI color codes
--SKIPIF--
<?php if (!(@include 'Console/Color2.php')) echo 'skip Console_Color2 not installed'; ?>
--FILE--
<?php
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
require_once 'Console/Color2.php';
$cc = new Console_Color2();
$table = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, CONSOLE_TABLE_BORDER_ASCII, 1, null, true);
$table->setHeaders(array('foo', 'bar'));
$table->addRow(array('baz', $cc->convert("%bblue%n")));
echo $table->getTable();
?>
--EXPECT--
+-----+------+
| foo | bar |
+-----+------+
| baz | blue |
+-----+------+

View file

@ -0,0 +1,38 @@
--TEST--
Callback filters
--FILE--
<?php
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$data = array(
array('one', 'two'),
array('three', 'four'),
CONSOLE_TABLE_HORIZONTAL_RULE,
array('five', 'six'),
array('seven', 'eight'),
);
$filter = 'strtoupper';
$table = new Console_Table();
$table->setHeaders(array('foo', 'bar'));
$table->addData($data);
$table->addFilter(0, $filter);
echo $table->getTable();
?>
--EXPECT--
+-------+-------+
| foo | bar |
+-------+-------+
| ONE | two |
| THREE | four |
+-------+-------+
| FIVE | six |
| SEVEN | eight |
+-------+-------+

View file

@ -0,0 +1,35 @@
--TEST--
Multibyte strings
--FILE--
<?php
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table();
$table->setHeaders(array('Schön', 'Häßlich'));
$table->addData(array(array('Ich', 'Du'), array('Ä', 'Ü')));
echo $table->getTable();
$table = new Console_Table();
$table->addRow(array("I'm from 中国"));
$table->addRow(array("我是中国人"));
$table->addRow(array("I'm from China"));
echo $table->getTable();
?>
--EXPECT--
+-------+---------+
| Schön | Häßlich |
+-------+---------+
| Ich | Du |
| Ä | Ü |
+-------+---------+
+----------------+
| I'm from 中国 |
| 我是中国人 |
| I'm from China |
+----------------+

View file

@ -0,0 +1,51 @@
--TEST--
Multiline table cells
--FILE--
<?php
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$data = array(
array('col1', '0', "col3\nmultiline", 'col4'),
array('r2col1', 'r2col2', "r2col3\nmultiline", 'r2col4'),
array('r3col1', 'r3col2', "r3col3\nmultiline\r\nverymuch", 'r3col4'),
array('r4col1', 'r4col2', "r4col3", 'r4col4'),
array('r5col1', 'r5col2', "r5col3", 'r5col4'),
);
$table = new Console_Table();
$table->setHeaders(array("h1\nmultiline", 'h2', "h3", 'h4'));
$table->addData($data);
echo $table->getTable();
echo Console_Table::fromArray(array('one line header'),
array(array("multiple\nlines"),
array('one line')));
?>
--EXPECT--
+-----------+--------+-----------+--------+
| h1 | h2 | h3 | h4 |
| multiline | | | |
+-----------+--------+-----------+--------+
| col1 | 0 | col3 | col4 |
| | | multiline | |
| r2col1 | r2col2 | r2col3 | r2col4 |
| | | multiline | |
| r3col1 | r3col2 | r3col3 | r3col4 |
| | | multiline | |
| | | verymuch | |
| r4col1 | r4col2 | r4col3 | r4col4 |
| r5col1 | r5col2 | r5col3 | r5col4 |
+-----------+--------+-----------+--------+
+-----------------+
| one line header |
+-----------------+
| multiple |
| lines |
| one line |
+-----------------+

View file

@ -0,0 +1,21 @@
--TEST--
Table without header
--FILE--
<?php
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table();
$table->addData(array(array('foo', 'bar')));
echo $table->getTable();
?>
--EXPECT--
+-----+-----+
| foo | bar |
+-----+-----+

View file

@ -0,0 +1,25 @@
--TEST--
Table without data
--FILE--
<?php
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$table = new Console_Table();
$table->setHeaders(array('foo', 'bar'));
echo $table->getTable();
$table = new Console_Table();
echo $table->getTable();
?>
--EXPECT--
+-----+-----+
| foo | bar |
+-----+-----+
| | |
+-----+-----+

View file

@ -0,0 +1,74 @@
--TEST--
Horizontal rules
--FILE--
<?php
if (file_exists(dirname(__FILE__) . '/../Table.php')) {
require_once dirname(__FILE__) . '/../Table.php';
} else {
require_once 'Console/Table.php';
}
$data = array(
array('one', 'two'),
CONSOLE_TABLE_HORIZONTAL_RULE,
array('three', 'four'),
CONSOLE_TABLE_HORIZONTAL_RULE,
CONSOLE_TABLE_HORIZONTAL_RULE,
array('five', 'six'),
array('seven', 'eight'),
);
$table = new Console_Table();
$table->setHeaders(array('foo', 'bar'));
$table->addData($data);
$table->addSeparator();
echo $table->getTable();
echo "=========================\n";
$table = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, '');
$table->setHeaders(array('foo', 'bar'));
$table->addData($data);
$table->addSeparator();
echo $table->getTable();
echo "=========================\n";
$table = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, '#', 0);
$table->setHeaders(array('foo', 'bar'));
$table->addData($data);
$table->addSeparator();
echo $table->getTable();
?>
--EXPECT--
+-------+-------+
| foo | bar |
+-------+-------+
| one | two |
+-------+-------+
| three | four |
+-------+-------+
+-------+-------+
| five | six |
| seven | eight |
+-------+-------+
+-------+-------+
=========================
foo bar
one two
three four
five six
seven eight
=========================
#############
#foo #bar #
#############
#one #two #
#############
#three#four #
#############
#############
#five #six #
#seven#eight#
#############
#############