Skip to content

Commit f6feaa2

Browse files
committed
Add test case for wrapping text with colors
1 parent 8189c68 commit f6feaa2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/TableFormatterTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,51 @@ public function test_onewrap()
138138
$result = $tf->format([5, '*'], [$col1, $col2]);
139139
$this->assertEquals($expect, $result);
140140
}
141+
142+
/**
143+
* Test that colors are correctly applied when text is wrapping across lines.
144+
*
145+
* @dataProvider colorwrapProvider
146+
*/
147+
public function test_colorwrap($text, $expect)
148+
{
149+
$tf = new TableFormatter();
150+
$tf->setMaxWidth(15);
151+
152+
$this->assertEquals($expect, $tf->format(['*'], [$text]));
153+
}
154+
155+
/**
156+
* Data provider for test_colorwrap.
157+
*
158+
* @return array[]
159+
*/
160+
public function colorwrapProvider()
161+
{
162+
$color = new Colors();
163+
$cyan = $color->getColorCode(Colors::C_CYAN);
164+
$reset = $color->getColorCode(Colors::C_RESET);
165+
$wrap = function ($str) use ($color) {
166+
return $color->wrap($str, Colors::C_CYAN);
167+
};
168+
169+
return [
170+
'color word line 1' => [
171+
"This is ". $wrap("cyan") . " text wrapping",
172+
"This is {$cyan}cyan{$reset} \ntext wrapping \n",
173+
],
174+
'color word line 2' => [
175+
"This is text ". $wrap("cyan") . " wrapping",
176+
"This is text \n{$cyan}cyan{$reset} wrapping \n",
177+
],
178+
'color across lines' => [
179+
"This is ". $wrap("cyan text",) . " wrapping",
180+
"This is {$cyan}cyan \ntext{$reset} wrapping \n",
181+
],
182+
'color across lines until end' => [
183+
"This is ". $wrap("cyan text wrapping"),
184+
"This is {$cyan}cyan \n{$cyan}text wrapping{$reset} \n",
185+
],
186+
];
187+
}
141188
}

0 commit comments

Comments
 (0)