Skip to content

Commit

Permalink
All line numbers in tables are padded to the left (#133)
Browse files Browse the repository at this point in the history
Now all line numbers in tables are padded to the left. This improves
readability especially for larger tables with many entries and enhances
consistence in data presentation across the different outputs.
  • Loading branch information
SmetDenis committed Apr 3, 2024
1 parent 014cbd2 commit 01e1be4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 59 deletions.
22 changes: 11 additions & 11 deletions README.md
Expand Up @@ -999,7 +999,7 @@ Pairs by pattern: 1
Check schema syntax: 1
2 issues in ./tests/schemas/demo_invalid.yml
+-------+------------------+--------------+----------------------------------------------------------------------+
| Line | id:Column | Rule | Message |
| Line | id:Column | Rule | Message |
+-------+------------------+--------------+----------------------------------------------------------------------+
| undef | 2:Float | is_float | Value "Qwerty" is not a float number |
| undef | 4:Favorite color | allow_values | Value "123" is not allowed. Allowed values: ["red", "green", "Blue"] |
Expand All @@ -1011,19 +1011,19 @@ Schema: ./tests/schemas/demo_invalid.yml
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
| Line | id:Column | Rule | Message |
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
| 1 | | allow_extra_columns | Column(s) not found in CSV: "wrong_column_name" |
| 6 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
| 11 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 9, total: 10 |
| 2 | 2:Float | num_max | The value "4825.185" is greater than the expected "4825.184" |
| 1 | 2:Float | ag:nth_num | The N-th value in the column is "74", which is not equal than the expected "0.001" |
| 6 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
| 1 | | allow_extra_columns | Column(s) not found in CSV: "wrong_column_name" |
| 6 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
| 11 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 9, total: 10 |
| 2 | 2:Float | num_max | The value "4825.185" is greater than the expected "4825.184" |
| 1 | 2:Float | ag:nth_num | The N-th value in the column is "74", which is not equal than the expected "0.001" |
| 6 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
| | | | expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
| 8 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
| 8 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
| | | | expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
| 9 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater than |
| 9 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater than |
| | | | the expected "2009-01-01 00:00:00 +00:00 (2009-01-01)" |
| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
Summary:
Expand Down
4 changes: 3 additions & 1 deletion src/Validators/ErrorSuite.php
Expand Up @@ -25,6 +25,7 @@
use JBZoo\Utils\FS;
use JBZoo\Utils\Vars;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableStyle;
use Symfony\Component\Console\Output\BufferedOutput;

final class ErrorSuite
Expand Down Expand Up @@ -157,7 +158,8 @@ private function renderTable(): string
->setColumnMaxWidth(0, $floatingSizes['line'])
->setColumnMaxWidth(1, $floatingSizes['column'])
->setColumnMaxWidth(2, $floatingSizes['rule'])
->setColumnMaxWidth(3, $floatingSizes['message']);
->setColumnMaxWidth(3, $floatingSizes['message'])
->setColumnStyle(0, (new TableStyle())->setPadType(\STR_PAD_LEFT));

foreach ($this->errors as $error) {
$table->addRow([
Expand Down
34 changes: 17 additions & 17 deletions tests/Commands/ValidateCsvBasicTest.php
Expand Up @@ -80,8 +80,8 @@ public function testValidateOneCsvNegative(): void
+------+------------------+--------------+----------------------------------------------------------------------------------------+
| Line | id:Column | Rule | Message |
+------+------------------+--------------+----------------------------------------------------------------------------------------+
| 6 | 0:Name | length_max | The length of the value "Long-long-name" is 14, which is greater than the expected "7" |
| 11 | 4:Favorite color | allow_values | Value "YELLOW" is not allowed. Allowed values: ["red", "green", "blue"] |
| 6 | 0:Name | length_max | The length of the value "Long-long-name" is 14, which is greater than the expected "7" |
| 11 | 4:Favorite color | allow_values | Value "YELLOW" is not allowed. Allowed values: ["red", "green", "blue"] |
+------+------------------+--------------+----------------------------------------------------------------------------------------+
Summary:
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testValidateOneCsvWithInvalidSchemaNegative(): void
Check schema syntax: 1
2 issues in ./tests/schemas/demo_invalid.yml
+-------+------------------+--------------+----------------------------------------------------------------------+
| Line | id:Column | Rule | Message |
| Line | id:Column | Rule | Message |
+-------+------------------+--------------+----------------------------------------------------------------------+
| undef | 2:Float | is_float | Value "Qwerty" is not a float number |
| undef | 4:Favorite color | allow_values | Value "123" is not allowed. Allowed values: ["red", "green", "Blue"] |
Expand All @@ -124,19 +124,19 @@ public function testValidateOneCsvWithInvalidSchemaNegative(): void
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
| Line | id:Column | Rule | Message |
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
| 1 | | allow_extra_columns | Column(s) not found in CSV: "wrong_column_name" |
| 6 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
| 11 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 9, total: 10 |
| 2 | 2:Float | num_max | The value "4825.185" is greater than the expected "4825.184" |
| 1 | 2:Float | ag:nth_num | The N-th value in the column is "74", which is not equal than the expected "0.001" |
| 6 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
| 1 | | allow_extra_columns | Column(s) not found in CSV: "wrong_column_name" |
| 6 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
| 11 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 9, total: 10 |
| 2 | 2:Float | num_max | The value "4825.185" is greater than the expected "4825.184" |
| 1 | 2:Float | ag:nth_num | The N-th value in the column is "74", which is not equal than the expected "0.001" |
| 6 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
| | | | expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
| 8 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
| 8 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
| | | | expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
| 9 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater than |
| 9 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater than |
| | | | the expected "2009-01-01 00:00:00 +00:00 (2009-01-01)" |
| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
Summary:
Expand Down Expand Up @@ -171,7 +171,7 @@ public function testInvalidSchemaNotMatched(): void
Check schema syntax: 1
8 issues in ./tests/schemas/invalid_schema.yml
+-------+------------+--------+-------------------------------------------------------------------------+
| Line | id:Column | Rule | Message |
| Line | id:Column | Rule | Message |
+-------+------------+--------+-------------------------------------------------------------------------+
| undef | meta | schema | Unknown key: .unknow_root_option |
| undef | meta | schema | Unknown key: .csv.unknow_csv_param |
Expand Down Expand Up @@ -219,7 +219,7 @@ public function testInvalidSchemaAndNotFoundCSV(): void
Check schema syntax: 1
8 issues in ./tests/schemas/invalid_schema.yml
+-------+------------+--------+-------------------------------------------------------------------------+
| Line | id:Column | Rule | Message |
| Line | id:Column | Rule | Message |
+-------+------------+--------+-------------------------------------------------------------------------+
| undef | meta | schema | Unknown key: .unknow_root_option |
| undef | meta | schema | Unknown key: .csv.unknow_csv_param |
Expand Down Expand Up @@ -269,8 +269,8 @@ public function testValidateOneCsvNoHeaderNegative(): void
+------+-----------+------------------+------------------------------+
| Line | id:Column | Rule | Message |
+------+-----------+------------------+------------------------------+
| 2 | 0: | not_allow_values | Value "Clyde" is not allowed |
| 5 | 2: | not_allow_values | Value "74" is not allowed |
| 2 | 0: | not_allow_values | Value "Clyde" is not allowed |
| 5 | 2: | not_allow_values | Value "74" is not allowed |
+------+-----------+------------------+------------------------------+
Summary:
Expand Down

0 comments on commit 01e1be4

Please sign in to comment.