[Console] fixed the formatter for single-char tags

This commit is contained in:
Fabien Potencier 2013-09-17 14:13:58 +02:00
parent c6c35b3db9
commit a47d663f25
2 changed files with 6 additions and 3 deletions

View File

@ -23,7 +23,7 @@ class OutputFormatter implements OutputFormatterInterface
/**
* The pattern to phrase the format.
*/
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>((?: [^<\\\\]+ | (?!<(?:/?[a-z]|/>)). | .(?<=\\\\<) )*)#isx';
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]*)?>((?: [^<\\\\]+ | (?!<(?:/?[a-z]|/>)). | .(?<=\\\\<) )*)#isx';
private $decorated;
private $styles = array();

View File

@ -113,7 +113,10 @@ class FormatterStyleTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($style, $formatter->getStyle('test'));
$this->assertNotEquals($style, $formatter->getStyle('info'));
$this->assertEquals("\033[34;47msome custom msg\033[0m", $formatter->format('<test>some custom msg</test>'));
$style = new OutputFormatterStyle('blue', 'white');
$formatter->setStyle('b', $style);
$this->assertEquals("\033[34;47msome \033[0m\033[34;47mcustom\033[0m\033[34;47m msg\033[0m", $formatter->format('<test>some <b>custom</b> msg</test>'));
}
public function testRedefineStyle()
@ -137,7 +140,7 @@ class FormatterStyleTest extends \PHPUnit_Framework_TestCase
public function testNonStyleTag()
{
$formatter = new OutputFormatter(true);
$this->assertEquals("\033[32msome \033[0m\033[32m<tag> styled\033[0m", $formatter->format('<info>some <tag> styled</info>'));
$this->assertEquals("\033[32msome \033[0m\033[32m<tag> styled \033[0m\033[32m<p>single-char tag\033[0m\033[32m</p>\033[0m", $formatter->format('<info>some <tag> styled <p>single-char tag</p></info>'));
}
public function testNotDecoratedFormatter()