CSS-Prepare

 view release on metacpan or  search on metacpan

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

        ok( ! is_percentage_value( $value ),
            "not percentage: '$value'" );
    }

    my @valid_percentage_values = qw( 0.254338% +150% -5% );
    foreach my $value ( @valid_percentage_values ) {
        ok( is_percentage_value( $value ),
            "percentage: '$value'" );
        ok( ! is_length_value( $value ),
            "not length: '$value'" );
    }
}

# test strings
{
    my @strings = ( '"hello"', q('hello'), qq('that\\'s mine'), qq("\\"") );
    foreach my $value ( @strings ) {
        ok( is_string_value( $value ),
            "string: ($value)" );
    }
    ok( ! is_string_value( q('it's here') ),
        "not string: ('it's here')" );
}

# test url values
{
    # co-incidentally also tests string values
    my @valid_url_values = (
            'url(blah.gif)',
            'url( blah\).gif )',
            'url( http://www.example.com/blah.gif )',
            q(url( 'bob.gif' )),
            'url( "https://secure.example.com/blah.gif" )',
        );
    foreach my $value ( @valid_url_values ) {
        ok( is_url_value( $value ),
            "url: '$value'" );
    }

    my @invalid_url_values = (
            'blah.gif',
            'png(something.png)',
        );
    foreach my $value ( @invalid_url_values ) {
        ok( ! is_url_value( $value ),
            "not url: '$value'" );
    }
}

# test background values
{
    foreach my $value qw( scroll fixed inherit ) {
        ok( is_background_attachment_value( $value ),
            "background-attachment: '$value'" );
    }
    ok( ! is_background_attachment_value( 'relative' ),
        "not background-attachment: 'relative'" );
    
    
    # other background-color values are tested by colours above
    my @colours = ( 'inherit', 'transparent', 'red', '#000' );
    foreach my $value ( @colours ) {
        ok( is_background_colour_value( $value ),
            "background-color: '$value'" );
    }
    ok( ! is_background_colour_value( '#cc' ),
        "not background-color: '#cc'" );
    
    
    # other background-image values are tested by urls above
    foreach my $value qw( none  url(blah.gif)  inherit ) {
        ok( is_background_image_value( $value ),
            "background-image: '$value'" );
    }
    ok( ! is_background_image_value( 'blah.gif'),
        "not background-image: 'blah.gif'" );
    
    
    foreach my $value qw( repeat repeat-x repeat-y no-repeat inherit ) {
        ok( is_background_repeat_value( $value ),
            "background-repeat: '$value'" );
    }
    ok( ! is_background_repeat_value( 'repeat-z' ),
        "not background-repeat: 'repeat-z'" );
    
    
    my @positions = (
            'left', 'center', 'centre', 'right', 'top', 'bottom',
            'left center', 'center center', 'centre centre',
            'left top', 'top left', 'top right',
            'bottom left', 'bottom right', 'top left', 'top right',
            '50%', '10px', '50% 50%', '10px top', 'left 50%',
            'inherit',
        );
    foreach my $value ( @positions ) {
        ok( is_background_position_value( $value ),
            "background-position: '$value'" );
    }
    ok( ! is_background_position_value( '50% left' ),
        "not background-position: '50% left'" );
    ok( ! is_background_position_value( 'bottom 50%' ),
        "not background-position: 'bottom 50%'" );
}

# test border values
{
    my @border_style_values = qw(
            none     hidden  dotted  dashed  solid
            double   groove  ridge   inset   outset
            inherit
        );
    foreach my $value ( @border_style_values ) {
        ok( is_border_style_value( $value ),
            "border-style: '$value'" );
    }
    ok( ! is_border_style_value( 'groovy' ),
        "not border-style: 'groovy'" );
    
    # other border-width values are tested by numerical values above
    foreach my $value qw( thin  medium  thick  inherit  2px ) {
        ok( is_border_width_value( $value ),
            "border-width: '$value'" );
    }
    ok( ! is_border_width_value( 'stroke' ),
        "not border-width: 'stroke'" );
    ok( ! is_border_width_value( '-2px' ),
        "not border-width: '-2px'" );
    
    # other border-color values are tested by colours above
    my @colours = ( 'inherit', 'transparent', 'red', '#000' );
    foreach my $value ( @colours ) {
        ok( is_border_colour_value( $value ),
            "border-color: '$value'" );
    }
    ok( ! is_border_colour_value( '#cc' ),
        "not border-color: '#cc'" );
    
    my @corner_radii = (
            '5px', '5px 2px', '.5em 1px',
        );
    foreach my $value ( @corner_radii ) {
        ok( is_border_radius_corner_value( $value ),
            "border-radius corner: '$value'" );
    }
    
    my @radii = ( '5em 2em 1em', '5em / 1px 2px 3px 4px' );
    foreach my $value ( @corner_radii, @radii ) {
        ok( is_border_radius_value( $value ),
            "border-radius: '$value'" );
    }
    
    foreach my $value ( @radii ) {
        ok( ! is_border_radius_corner_value( $value ),
            "not border-radius corner: '$value'" );
    }
}

# test margins and padding
{
    # other lengths and percentages are tested above
    ok( is_margin_width_value( '5px' ),
        "margin-width: '5px'" );
    ok( is_margin_width_value( '-2em' ),
        "margin-width: '-2em'" );
    ok( is_margin_width_value( '10%' ),
        "margin-width: '10%'" );
    ok( is_margin_width_value( 'auto' ),
        "margin-width: 'auto'" );
    ok( is_margin_width_value( 'inherit' ),
        "margin-width: 'inherit'" );
    ok( ! is_margin_width_value( '20' ),
        "not margin-width: '20'" );
    
    
    ok( is_padding_width_value( '5px' ),
        "padding-width: '5px'" );
    ok( ! is_padding_width_value( '-2em' ),
        "not padding-width: '-2em'" );
    ok( is_padding_width_value( '10%' ),
        "padding-width: '10%'" );
    ok( is_padding_width_value( 'inherit' ),
        "padding-width: 'inherit'" );
    ok( ! is_padding_width_value( '20' ),
        "not padding-width: '20'" );
}

# test visual formatting
{
    my @valid_display_values = qw(
            block               inline              inline-block

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

            "clip: '$value'" );
    }
    ok( ! is_clip_value( 'square' ),
        "not clip: 'square'" );
    
    
    foreach my $value qw( visible  hidden  collapse  inherit ) {
        ok( is_visibility_value( $value ),
            "visibility: '$value'" );
    }
    ok( ! is_visibility_value( 'invisible' ),
        "not visibility: 'invisible'" );
}

# test user interface
{
    my @cursors = qw(
            auto       crosshair  default    pointer    move       e-resize
            ne-resize  nw-resize  n-resize   se-resize  sw-resize  s-resize
            w-resize   text       wait       help       progress
            inherit
        );
    foreach my $value ( @cursors ) {
        ok( is_cursor_value( $value ),
            "cursor: '$value'" );
    }
    ok( is_cursor_value( 'url(blah.gif) crosshair' ),
        "cursor: 'url(blah.gif) crosshair'" );
    ok( ! is_cursor_value( 'url(blah.gif)' ),
        "not cursor: 'url(blah.gif)'" );
    ok( ! is_cursor_value( 'crosshair sw-resize' ),
        "not cursor: 'crosshair sw-resize'" );
    
    
    my @outline_style_values = qw(
            none     hidden  dotted  dashed  solid
            double   groove  ridge   inset   outset
            inherit
        );
    foreach my $value ( @outline_style_values ) {
        ok( is_outline_style_value( $value ),
            "outline-style: '$value'" );
    }
    ok( ! is_outline_style_value( 'groovy' ),
        "not outline-style: 'groovy'" );
    
    # other outline-width values are tested by numerical values above
    foreach my $value qw( thin  medium  thick  inherit  2px ) {
        ok( is_outline_width_value( $value ),
            "outline-width: '$value'" );
    }
    ok( ! is_outline_width_value( 'stroke' ),
        "not outline-width: 'stroke'" );
    
    # other outline-color values are tested by colours above
    my @colours = ( 'inherit', 'invert', 'red', '#000' );
    foreach my $value ( @colours ) {
        ok( is_outline_colour_value( $value ),
            "outline-color: '$value'" );
    }
    ok( ! is_outline_colour_value( 'transparent' ),
        "not outline-color: 'transparent'" );
    ok( ! is_outline_colour_value( '#cc' ),
        "not outline-color: '#cc'" );
}



( run in 1.695 second using v1.01-cache-2.11-cpan-39bf76dae61 )