Skip to content
This repository was archived by the owner on Jun 18, 2022. It is now read-only.

Commit a32db1a

Browse files
author
armab
committed
Add tests for colored string in ASCII table
1 parent d75d532 commit a32db1a

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

tests/test-cli.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ function test_encoded_string_pad() {
2828
$this->assertEquals( 7, strlen( \cli\Colors::pad( 'óra', 6 ) ) ); // special characters take one byte
2929
$this->assertEquals( 9, strlen( \cli\Colors::pad( '日本語', 6 ) ) ); // each character takes two bytes
3030
$this->assertEquals( 17, strlen( \cli\Colors::pad( 'עִבְרִית', 6 ) ) ); // process Hebrew vowels
31+
}
3132

33+
function test_colorized_string_pad() {
34+
$this->assertEquals( 22, strlen( \cli\Colors::pad( \cli\Colors::colorize( "%Gx%n", true ), 11 ))); // colorized `x` string
35+
$this->assertEquals( 23, strlen( \cli\Colors::pad( \cli\Colors::colorize( "%Góra%n", true ), 11 ))); // colorized `óra` string
3236
}
3337

3438
function test_encoded_substr() {

tests/test-table-ascii.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,36 @@ public function testDrawOneColumnTable() {
5757
| x |
5858
+-------------+
5959

60+
OUT;
61+
$this->assertInOutEquals(array($headers, $rows), $output);
62+
}
63+
64+
/**
65+
* Draw simple One column table with colored string
66+
* Output should look like:
67+
* +-------------+
68+
* | Test Header |
69+
* +-------------+
70+
* | x |
71+
* +-------------+
72+
*
73+
* where `x` character has green color.
74+
* At the same time it checks that `green` defined in `cli\Colors` really looks as `green`.
75+
*/
76+
public function testDrawOneColumnColoredTable() {
77+
$headers = array('Test Header');
78+
$rows = array(
79+
array(Colors::colorize('%Gx%n', true)),
80+
);
81+
// green `x`
82+
$x = "\x1B\x5B\x33\x32\x3B\x31\x6Dx\x1B\x5B\x30\x6D";
83+
$output = <<<OUT
84+
+-------------+
85+
| Test Header |
86+
+-------------+
87+
| $x |
88+
+-------------+
89+
6090
OUT;
6191
$this->assertInOutEquals(array($headers, $rows), $output);
6292
}

0 commit comments

Comments
 (0)