CSS-Minifier-XS
view release on metacpan or search on metacpan
#!/usr/bin/perl
use strict;
use warnings;
use if $ENV{AUTOMATED_TESTING}, 'Test::DiagINC'; use Test::More;
use CSS::Minifier::XS qw(minify);
###############################################################################
# Removal of leading whitespace, regardless of "space", "tab", "CR", "LF".
subtest 'leading whitespace can be removed' => sub {
my $given = "\n\n\r\t\n \n h1 { }";
my $expect = 'h1{}';
my $got = minify($given);
is $got, $expect;
};
###############################################################################
# Removal of trailing whitespace, regardless of "space", "tab", "CR", "LF".
subtest 'trailing whitespace can be removed' => sub {
my $given = "h1 { } \t\n\r\n";
my $expect = 'h1{}';
my $got = minify($given);
is $got, $expect;
};
###############################################################################
# Whitespace that trails a ")" may be preserved.
subtest 'whitespace trailing a ")"' => sub {
subtest 'end of statement; removed' => sub {
my $given = 'div { background: url(foo.gif) ; }';
my $expect = 'div{background:url(foo.gif)}';
my $got = minify($given);
is $got, $expect;
};
subtest 'inside of statement; preserved' => sub {
my $given = 'div { background: url(foo.gif) no-repeat; }';
my $expect = 'div{background:url(foo.gif) no-repeat}';
my $got = minify($given);
is $got, $expect;
};
};
###############################################################################
# Removal of trailing semi-colons, at end of a group.
subtest 'trailing semi-colons' => sub {
subtest 'at end of group; removed' => sub {
my $given = 'h1 { font-weight: bold; }';
my $expect = 'h1{font-weight:bold}';
my $got = minify($given);
is $got, $expect;
};
subtest 'inside of group; preserved' => sub {
my $given = 'h1 { font-weight: bold; color: red;}';
my $expect = 'h1{font-weight:bold;color:red}';
my $got = minify($given);
is $got, $expect;
};
};
###############################################################################
# Comments get minified and removed, UNLESS they contain the word
# "copyright" in them.
subtest 'comments' => sub {
subtest 'block comment removed' => sub {
my $given = '/* comment */ h1 { background: green }';
my $expect = 'h1{background:green}';
my $got = minify($given);
is $got, $expect;
};
subtest 'copyright comment remains' => sub {
my $given = '/* comment with copyright */ h1 { color: red }';
my $expect = '/* comment with copyright */h1{color:red}';
my $got = minify($given);
is $got, $expect;
};
subtest 'copyright is case in-sensitive' => sub {
my $given = '/* comment with CoPyRiGhT */ h1 { color: red }';
my $expect = '/* comment with CoPyRiGhT */h1{color:red}';
my $got = minify($given);
is $got, $expect;
};
};
###############################################################################
# Comments with the "Mac/IE Comment Hack" are preserved, but minified.
subtest 'mac/ie comment hack' => sub {
subtest 'comment hack is minified' => sub {
my $given = '/* start \*/ ul { color: red } /* end */';
my $expect = '/*\*/ul{color:red}/**/';
my $got = minify($given);
is $got, $expect;
};
subtest 'inner hacks are removed' => sub {
my $given = '/* start \*/ ul { /* inner \*/ color: red } /* end */';
my $expect = '/*\*/ul{color:red}/**/';
my $got = minify($given);
is $got, $expect;
};
};
###############################################################################
# "!important" declarations can have preceeding whitespace removed.
subtest '!important' => sub {
my $given = 'a { box-shadow: none !important; }';
my $expect = 'a{box-shadow:none!important}';
my $got = minify($given);
is $got, $expect;
};
###############################################################################
# CSS Selector Combinators get whitespace removed
( run in 0.598 second using v1.01-cache-2.11-cpan-39bf76dae61 )