Skip to content

Commit

Permalink
Additional tests to include all themes and reversed colouring.
Browse files Browse the repository at this point in the history
Unit tests now provide 100% code coverage.
  • Loading branch information
Richard Quadling authored and Richard Quadling committed Oct 10, 2019
1 parent 9bb755b commit 444c15d
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace SensioLabs\AnsiConverter\Tests\AlternativeTheme;

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
use SensioLabs\AnsiConverter\Theme\SolarizedXTermTheme;
use SensioLabs\AnsiConverter\Theme\SolarizedTheme;

class AnsiToHtmlConverterWithAlternativeCSSPrefixTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -21,46 +21,46 @@ class AnsiToHtmlConverterWithAlternativeCSSPrefixTest extends \PHPUnit_Framework
*/
public function testConvert($expectedOutput, $expectedCss, $input)
{
$converter = new AnsiToHtmlConverter(new SolarizedXTermTheme(), false, 'UTF-8', 'alternative_prefix');
$converter = new AnsiToHtmlConverter(new SolarizedTheme(), false, 'UTF-8', 'alternative_prefix');
$this->assertEquals($expectedOutput, $converter->convert($input));
$this->assertEquals($expectedCss, $converter->getTheme()->asCss());
}

public function getConvertData()
{
$css = <<< 'END_CSS'
.alternative_prefix_fg_black { color: #262626 }
.alternative_prefix_bg_black { background-color: #262626 }
.alternative_prefix_fg_red { color: #d70000 }
.alternative_prefix_bg_red { background-color: #d70000 }
.alternative_prefix_fg_green { color: #5f8700 }
.alternative_prefix_bg_green { background-color: #5f8700 }
.alternative_prefix_fg_yellow { color: #af8700 }
.alternative_prefix_bg_yellow { background-color: #af8700 }
.alternative_prefix_fg_blue { color: #0087ff }
.alternative_prefix_bg_blue { background-color: #0087ff }
.alternative_prefix_fg_magenta { color: #af005f }
.alternative_prefix_bg_magenta { background-color: #af005f }
.alternative_prefix_fg_cyan { color: #00afaf }
.alternative_prefix_bg_cyan { background-color: #00afaf }
.alternative_prefix_fg_white { color: #e4e4e4 }
.alternative_prefix_bg_white { background-color: #e4e4e4 }
.alternative_prefix_fg_brblack { color: #1c1c1c }
.alternative_prefix_bg_brblack { background-color: #1c1c1c }
.alternative_prefix_fg_brred { color: #d75f00 }
.alternative_prefix_bg_brred { background-color: #d75f00 }
.alternative_prefix_fg_brgreen { color: #585858 }
.alternative_prefix_bg_brgreen { background-color: #585858 }
.alternative_prefix_fg_bryellow { color: #626262 }
.alternative_prefix_bg_bryellow { background-color: #626262 }
.alternative_prefix_fg_brblue { color: #808080 }
.alternative_prefix_bg_brblue { background-color: #808080 }
.alternative_prefix_fg_brmagenta { color: #5f5faf }
.alternative_prefix_bg_brmagenta { background-color: #5f5faf }
.alternative_prefix_fg_brcyan { color: #8a8a8a }
.alternative_prefix_bg_brcyan { background-color: #8a8a8a }
.alternative_prefix_fg_brwhite { color: #ffffd7 }
.alternative_prefix_bg_brwhite { background-color: #ffffd7 }
.alternative_prefix_fg_black { color: #073642 }
.alternative_prefix_bg_black { background-color: #073642 }
.alternative_prefix_fg_red { color: #dc322f }
.alternative_prefix_bg_red { background-color: #dc322f }
.alternative_prefix_fg_green { color: #859900 }
.alternative_prefix_bg_green { background-color: #859900 }
.alternative_prefix_fg_yellow { color: #b58900 }
.alternative_prefix_bg_yellow { background-color: #b58900 }
.alternative_prefix_fg_blue { color: #268bd2 }
.alternative_prefix_bg_blue { background-color: #268bd2 }
.alternative_prefix_fg_magenta { color: #d33682 }
.alternative_prefix_bg_magenta { background-color: #d33682 }
.alternative_prefix_fg_cyan { color: #2aa198 }
.alternative_prefix_bg_cyan { background-color: #2aa198 }
.alternative_prefix_fg_white { color: #eee8d5 }
.alternative_prefix_bg_white { background-color: #eee8d5 }
.alternative_prefix_fg_brblack { color: #002b36 }
.alternative_prefix_bg_brblack { background-color: #002b36 }
.alternative_prefix_fg_brred { color: #cb4b16 }
.alternative_prefix_bg_brred { background-color: #cb4b16 }
.alternative_prefix_fg_brgreen { color: #586e75 }
.alternative_prefix_bg_brgreen { background-color: #586e75 }
.alternative_prefix_fg_bryellow { color: #657b83 }
.alternative_prefix_bg_bryellow { background-color: #657b83 }
.alternative_prefix_fg_brblue { color: #839496 }
.alternative_prefix_bg_brblue { background-color: #839496 }
.alternative_prefix_fg_brmagenta { color: #6c71c4 }
.alternative_prefix_bg_brmagenta { background-color: #6c71c4 }
.alternative_prefix_fg_brcyan { color: #93a1a1 }
.alternative_prefix_bg_brcyan { background-color: #93a1a1 }
.alternative_prefix_fg_brwhite { color: #fdf6e3 }
.alternative_prefix_bg_brwhite { background-color: #fdf6e3 }
.alternative_prefix_underlined { text-decoration: underlined }
END_CSS;

Expand Down Expand Up @@ -92,6 +92,12 @@ public function getConvertData()

// non valid unicode codepoints substitution (only available with PHP >= 5.4)
PHP_VERSION_ID < 50400 ?: array('<span class="alternative_prefix_bg_black alternative_prefix_fg_white">foo '."\xEF\xBF\xBD".'</span>', $css, "foo \xF4\xFF\xFF\xFF"),

// Yellow on green.
array('<span class="alternative_prefix_bg_green alternative_prefix_fg_yellow">foo</span>', $css, "\e[33;42mfoo\e[0m"),

// Yellow on green - reversed.
array('<span class="alternative_prefix_bg_yellow alternative_prefix_fg_green">foo</span>', $css, "\e[33;42;7mfoo\e[0m"),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace SensioLabs\AnsiConverter\Tests\AlternativeTheme;

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
use SensioLabs\AnsiConverter\Theme\SolarizedXTermTheme;
use SensioLabs\AnsiConverter\Theme\SolarizedTheme;

class AnsiToHtmlConverterWithClassesTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -21,46 +21,46 @@ class AnsiToHtmlConverterWithClassesTest extends \PHPUnit_Framework_TestCase
*/
public function testConvert($expectedOutput, $expectedCss, $input)
{
$converter = new AnsiToHtmlConverter(new SolarizedXTermTheme(), false);
$converter = new AnsiToHtmlConverter(new SolarizedTheme(), false);
$this->assertEquals($expectedOutput, $converter->convert($input));
$this->assertEquals($expectedCss, $converter->getTheme()->asCss());
}

public function getConvertData()
{
$css = <<< 'END_CSS'
.ansi_color_fg_black { color: #262626 }
.ansi_color_bg_black { background-color: #262626 }
.ansi_color_fg_red { color: #d70000 }
.ansi_color_bg_red { background-color: #d70000 }
.ansi_color_fg_green { color: #5f8700 }
.ansi_color_bg_green { background-color: #5f8700 }
.ansi_color_fg_yellow { color: #af8700 }
.ansi_color_bg_yellow { background-color: #af8700 }
.ansi_color_fg_blue { color: #0087ff }
.ansi_color_bg_blue { background-color: #0087ff }
.ansi_color_fg_magenta { color: #af005f }
.ansi_color_bg_magenta { background-color: #af005f }
.ansi_color_fg_cyan { color: #00afaf }
.ansi_color_bg_cyan { background-color: #00afaf }
.ansi_color_fg_white { color: #e4e4e4 }
.ansi_color_bg_white { background-color: #e4e4e4 }
.ansi_color_fg_brblack { color: #1c1c1c }
.ansi_color_bg_brblack { background-color: #1c1c1c }
.ansi_color_fg_brred { color: #d75f00 }
.ansi_color_bg_brred { background-color: #d75f00 }
.ansi_color_fg_brgreen { color: #585858 }
.ansi_color_bg_brgreen { background-color: #585858 }
.ansi_color_fg_bryellow { color: #626262 }
.ansi_color_bg_bryellow { background-color: #626262 }
.ansi_color_fg_brblue { color: #808080 }
.ansi_color_bg_brblue { background-color: #808080 }
.ansi_color_fg_brmagenta { color: #5f5faf }
.ansi_color_bg_brmagenta { background-color: #5f5faf }
.ansi_color_fg_brcyan { color: #8a8a8a }
.ansi_color_bg_brcyan { background-color: #8a8a8a }
.ansi_color_fg_brwhite { color: #ffffd7 }
.ansi_color_bg_brwhite { background-color: #ffffd7 }
.ansi_color_fg_black { color: #073642 }
.ansi_color_bg_black { background-color: #073642 }
.ansi_color_fg_red { color: #dc322f }
.ansi_color_bg_red { background-color: #dc322f }
.ansi_color_fg_green { color: #859900 }
.ansi_color_bg_green { background-color: #859900 }
.ansi_color_fg_yellow { color: #b58900 }
.ansi_color_bg_yellow { background-color: #b58900 }
.ansi_color_fg_blue { color: #268bd2 }
.ansi_color_bg_blue { background-color: #268bd2 }
.ansi_color_fg_magenta { color: #d33682 }
.ansi_color_bg_magenta { background-color: #d33682 }
.ansi_color_fg_cyan { color: #2aa198 }
.ansi_color_bg_cyan { background-color: #2aa198 }
.ansi_color_fg_white { color: #eee8d5 }
.ansi_color_bg_white { background-color: #eee8d5 }
.ansi_color_fg_brblack { color: #002b36 }
.ansi_color_bg_brblack { background-color: #002b36 }
.ansi_color_fg_brred { color: #cb4b16 }
.ansi_color_bg_brred { background-color: #cb4b16 }
.ansi_color_fg_brgreen { color: #586e75 }
.ansi_color_bg_brgreen { background-color: #586e75 }
.ansi_color_fg_bryellow { color: #657b83 }
.ansi_color_bg_bryellow { background-color: #657b83 }
.ansi_color_fg_brblue { color: #839496 }
.ansi_color_bg_brblue { background-color: #839496 }
.ansi_color_fg_brmagenta { color: #6c71c4 }
.ansi_color_bg_brmagenta { background-color: #6c71c4 }
.ansi_color_fg_brcyan { color: #93a1a1 }
.ansi_color_bg_brcyan { background-color: #93a1a1 }
.ansi_color_fg_brwhite { color: #fdf6e3 }
.ansi_color_bg_brwhite { background-color: #fdf6e3 }
.ansi_color_underlined { text-decoration: underlined }
END_CSS;

Expand Down Expand Up @@ -92,6 +92,12 @@ public function getConvertData()

// non valid unicode codepoints substitution (only available with PHP >= 5.4)
PHP_VERSION_ID < 50400 ?: array('<span class="ansi_color_bg_black ansi_color_fg_white">foo '."\xEF\xBF\xBD".'</span>', $css, "foo \xF4\xFF\xFF\xFF"),

// Yellow on green.
array('<span class="ansi_color_bg_green ansi_color_fg_yellow">foo</span>', $css, "\e[33;42mfoo\e[0m"),

// Yellow on green - reversed.
array('<span class="ansi_color_bg_yellow ansi_color_fg_green">foo</span>', $css, "\e[33;42;7mfoo\e[0m"),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace SensioLabs\AnsiConverter\Tests\AlternativeTheme;

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
use SensioLabs\AnsiConverter\Theme\SolarizedXTermTheme;
use SensioLabs\AnsiConverter\Theme\SolarizedTheme;

class AnsiToHtmlConverterWithInlineStylesTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -21,40 +21,46 @@ class AnsiToHtmlConverterWithInlineStylesTest extends \PHPUnit_Framework_TestCas
*/
public function testConvertWith($expected, $input)
{
$converter = new AnsiToHtmlConverter(new SolarizedXTermTheme());
$converter = new AnsiToHtmlConverter(new SolarizedTheme());
$this->assertEquals($expected, $converter->convert($input));
}

public function getConvertData()
{
return array(
// text is escaped
array('<span style="background-color: #262626; color: #e4e4e4">foo &lt;br /&gt;</span>', 'foo <br />'),
array('<span style="background-color: #073642; color: #eee8d5">foo &lt;br /&gt;</span>', 'foo <br />'),

// newlines are preserved
array("<span style=\"background-color: #262626; color: #e4e4e4\">foo\nbar</span>", "foo\nbar"),
array("<span style=\"background-color: #073642; color: #eee8d5\">foo\nbar</span>", "foo\nbar"),

// backspaces
array('<span style="background-color: #262626; color: #e4e4e4">foo </span>', "foobar\x08\x08\x08 "),
array('<span style="background-color: #262626; color: #e4e4e4">foo</span><span style="background-color: #262626; color: #e4e4e4"> </span>', "foob\e[31;41ma\e[0mr\x08\x08\x08 "),
array('<span style="background-color: #073642; color: #eee8d5">foo </span>', "foobar\x08\x08\x08 "),
array('<span style="background-color: #073642; color: #eee8d5">foo</span><span style="background-color: #073642; color: #eee8d5"> </span>', "foob\e[31;41ma\e[0mr\x08\x08\x08 "),

// color
array('<span style="background-color: #d70000; color: #d70000">foo</span>', "\e[31;41mfoo\e[0m"),
array('<span style="background-color: #dc322f; color: #dc322f">foo</span>', "\e[31;41mfoo\e[0m"),

// color with [m as a termination (equivalent to [0m])
array('<span style="background-color: #d70000; color: #d70000">foo</span>', "\e[31;41mfoo\e[m"),
array('<span style="background-color: #dc322f; color: #dc322f">foo</span>', "\e[31;41mfoo\e[m"),

// bright color
array('<span style="background-color: #d75f00; color: #d75f00">foo</span>', "\e[31;41;1mfoo\e[0m"),
array('<span style="background-color: #cb4b16; color: #cb4b16">foo</span>', "\e[31;41;1mfoo\e[0m"),

// carriage returns
array('<span style="background-color: #262626; color: #e4e4e4">foobar</span>', "foo\rbar\rfoobar"),
array('<span style="background-color: #073642; color: #eee8d5">foobar</span>', "foo\rbar\rfoobar"),

// underline
array('<span style="background-color: #262626; color: #e4e4e4; text-decoration: underline">foo</span>', "\e[4mfoo\e[0m"),
array('<span style="background-color: #073642; color: #eee8d5; text-decoration: underline">foo</span>', "\e[4mfoo\e[0m"),

// non valid unicode codepoints substitution (only available with PHP >= 5.4)
PHP_VERSION_ID < 50400 ?: array('<span style="background-color: #262626; color: #e4e4e4">foo '."\xEF\xBF\xBD".'</span>', "foo \xF4\xFF\xFF\xFF"),
PHP_VERSION_ID < 50400 ?: array('<span style="background-color: #073642; color: #eee8d5">foo '."\xEF\xBF\xBD".'</span>', "foo \xF4\xFF\xFF\xFF"),

// Yellow on green.
array('<span style="background-color: #859900; color: #b58900">foo</span>', "\e[33;42mfoo\e[0m"),

// Yellow on green - reversed.
array('<span style="background-color: #b58900; color: #859900">foo</span>', "\e[33;42;7mfoo\e[0m"),
);
}
}
Loading

0 comments on commit 444c15d

Please sign in to comment.