CSS-Prepare

 view release on metacpan or  search on metacpan

t/01.parse.t  view on Meta::CPAN

use Modern::Perl;
use Test::More  tests => 28;

use CSS::Prepare;
use Data::Dumper;
local $Data::Dumper::Terse     = 1;
local $Data::Dumper::Indent    = 1;
local $Data::Dumper::Useqq     = 1;
local $Data::Dumper::Deparse   = 1;
local $Data::Dumper::Quotekeys = 0;
local $Data::Dumper::Sortkeys  = 1;


my $preparer = CSS::Prepare->new();
my( $css, @structure, @parsed );



# don't explode on an empty stylesheet
{
    $css = q();
    @structure = ();

    @parsed = $preparer->parse_string( $css );
    is_deeply( \@structure, \@parsed )
        or say "empty stylesheet was:\n" . Dumper \@parsed;
}

# basic declaration block
{
    $css = <<CSS;
        h1 { color: red; }
CSS
    @structure = (
            {
                original  => ' color: red; ',
                selectors => [ 'h1' ],
                errors    => [],
                block     => {
                    'color' => 'red',
                },
            },
        );

    @parsed = $preparer->parse_string( $css );
    is_deeply( \@structure, \@parsed )
        or say "basic declaration was:\n" . Dumper \@parsed;
}

# basic declaration block with lots of whitespace
{
    $css = <<CSS;
        h1 { 
            color      : red; 
        }
CSS
    @structure = (
            {
                original  => q( 
            color      : red; 
        ),



( run in 0.475 second using v1.01-cache-2.11-cpan-0d8aa00de5b )