Add parser for IE conditional comments, to be used in JS concatenation

This commit is contained in:
Kijin Sung 2016-05-04 18:06:02 +09:00
parent e22558374f
commit 90bce20794
3 changed files with 132 additions and 1 deletions

View file

@ -131,4 +131,33 @@ class FormatterTest extends \Codeception\TestCase\Test
unlink($test_target);
}
public function testConvertIECondition()
{
$this->assertEquals('window.navigator.userAgent.match(/MSIE\s/)', Rhymix\Framework\Formatter::convertIECondition('IE'));
$this->assertEquals('!window.navigator.userAgent.match(/MSIE\s/)', Rhymix\Framework\Formatter::convertIECondition('!IE'));
$this->assertEquals('!window.navigator.userAgent.match(/MSIE\s/)', Rhymix\Framework\Formatter::convertIECondition('!(IE)'));
$this->assertEquals('true && false', Rhymix\Framework\Formatter::convertIECondition('true&false'));
$this->assertEquals('false', Rhymix\Framework\Formatter::convertIECondition('gobbledygook'));
$source = 'gt IE 7';
$target = '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] > 7)';
$this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source));
$source = 'lte IE 8';
$target = '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] <= 8)';
$this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source));
$source = '(gte IE 6) & (lt IE 8)';
$target = '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] >= 6) && (/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < 8)';
$this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source));
$source = '!(gt IE 9)';
$target = '!(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] > 9)';
$this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source));
$source = '!lt IE 8|lt IE 6';
$target = '!(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < 8) || (/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < 6)';
$this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source));
}
}