CSS-DOM
view release on metacpan or search on metacpan
t/property-parser.t view on Meta::CPAN
{'border-top-color'},
'clone clones deeply';
is_deeply
$clone->get_property('border-color')->{properties}
{'border-top-color'},
$css21->get_property('border-color')->{properties}
{'border-top-color'},
'the values within the clone are still identical';
use tests 3; # add/get/delete_property
$parser->add_property("foo", my $prop = {});
is $parser->get_property("foo"), $prop, 'add/get_property';
is $parser->delete_property("foo"), $prop, 'delete_property retval';
is $parser->get_property("foo"), undef, 'effect of delete_property';
use tests 1; # property_names
$parser->add_property($_,{}) for reverse "a".."f";
is_deeply [$parser->property_names], ["a".."f"], 'property_names';
# ------------------------- CSS::DOM::Style ------------------------ #
require CSS::DOM::Style;
use tests 2; # invalid properties in parsing
my $s = CSS::DOM::Style::parse(
'azimuth: 0; azimuth: blue', property_parser => $css21
);
is $s->azimuth, '0',
'invalid property values are ignored in parsing (CSS::DOM::Style::parse)';
$s->cssText('');
$s->cssText('azimuth: 0; azimuth: blue'),
is $s->azimuth, 0, 'style->cssText ignores invalid values';
# ------------------------- CSS 2.1 tests ------------------------ #
use tests 28; # azimuth
for(qw/ left-side far-left left center-left center center-right right
far-right right-insidE behInd leftwards rightwards 0 0deg 80deg
60rad 38grad -0 +0 -80deg +80deg inherit /,
'left behind', 'behind center') {
$s->azimuth($_);
like $s->azimuth, qr/^\Q$_\E\z/i, "azimuth value: \L$_"
}
$s->azimuth('left');
for(qw/ 38 38cm upwards /, "center leftwards") {
$s->azimuth($_);
is $s->azimuth, 'left', "invalid azimuth value: $_";
}
use tests 3; # background-attachment
for(qw/ scroll fixed /) {
$s->backgroundAttachment($_);
is $s->backgroundAttachment, $_, "background-attachment value: \L$_"
}
$s->backgroundAttachment('38');
is $s->backgroundAttachment, 'fixed', "invalid bg-attachment value: 38";
use tests 197; # background-color
for(qw/ #abc #abcdef rgb(1,2,3) rgb(1%,2%,3%) rgba(1,2,3,4)
rgba(1%,2%,3%,4) transparent Aliceblue antiquewhitE aqua
aquamarine azure beige bisque black blanchedalmond blue blueviolet
brown burlywood cadetblue chartreuse chocolate coral cornflowerblue
cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray
darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange
darkorchid darkred darksalmon darkseagreen darkslateblue
darkslategray darkslategrey darkturquoise darkviolet deeppink
deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite
forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green
greenyellow grey honeydew hotpink indianred indigo ivory khaki
lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral
lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey
lightpink lightsalmon lightseagreen lightskyblue lightslategray
lightslategrey lightsteelblue lightyellow lime limegreen linen
magenta maroon mediumaquamarine mediumblue mediumorchid
mediumpurple mediumseagreen mediumslateblue mediumspringgreen
mediumturquoise mediumvioletred midnightblue mintcream mistyrose
moccasin navajowhite navy oldlace olive olivedrab orange orangered
orchid palegoldenrod palegreen paleturquoise palevioletred
papayawhip peachpuff peru pink plum powderblue purple red rosybrown
royalblue saddlebrown salmon sandybrown seagreen seashell sienna
silver skyblue slateblue slategray slategrey snow springgreen
steelblue tan teal thistle tomato turquoise violet wheat white
whitesmoke yellow yellowgreen activeborder activecaption
appworkspace background buttonface buttonhighlight buttonshadow
buttontext captiontext graytext highlight highlighttext
inactiveborder inactivecaption incativecaptiontext infobackground
infotext menu menutext scrollbar threeddarkshadow threedface
threedhighlight threedlightshadow threedshadow window windowframe
windowtext rgb(-5%,-6%,-7%) rgb(+5%,+6%,+7%) rgb(-5,-6,-7)
rgb(+5,+6,+7) rgba(-5%,-6%,-0%,-1) rgba(+5%,+6%,+7%,+5)
rgba(-5,-6,-0,-1) rgba(+5,+6,+7,+5)/) {
$s->backgroundColor($_);
my $__ = $s->backgroundColor;
for($__) {
s/ //g if /,/;
}
is $__, $_, "background-color value: \L$_"
}
$s->backgroundColor('white');
for(qw/ #1234 #defghi rgb(1%,2,3) rgb(1,2,3,4) rgba(1%,2,3,4)
rgba(1,2%,3%,4) SaladDressing /) {
$s->backgroundColor($_);
my $__ = $s->backgroundColor;
for($__) {
s/ //g if /,/;
}
is $__, 'white', "invalid bg-color value: $_";
}
use tests 3; # background-image
for(qw/ none url(foo) /) {
$s->backgroundImage($_);
is $s->backgroundImage, $_, "background-image value: \L$_"
}
$s->backgroundImage('38');
is $s->backgroundImage, 'url(foo)', "invalid bg-image value: 38";
use tests 57; # background-position
for('5%','-5%','+5%', '5% 5%', '5% 5px', '5% top', '5% bottom','5% center',
'5% bottom', '5em', '5ex', '5px', '5in', '5cm', '5mm', '5pt', '5pc', 0,
'-5px','-0','+0','+5px','5px 5%', '5px 5px', '5px top', '5px center',
'5px bottom','left','left 5%','left 5px','left top','left center',
'left bottom','center','center 5%','center 5px','center top',
'center center','center bottom','right','right 5%','right 5px',
'right top','right center','right bottom','top','top left',
'top center','top right','center left','center right','bottom',
'bottom left', 'bottom center', 'bottom right') {
$s->backgroundPosition($_);
is $s->backgroundPosition, $_, "background-position value: \L$_"
}
$s->backgroundPosition('left');
for("top bottom", "5% 5") {
$s->backgroundPosition($_);
is $s->backgroundPosition, 'left', "invalid bg-position value: $_";
}
use tests 6; # background-repeat
for(qw 'repeat repeat-x repeat-y no-repeat') {
$s->backgroundRepeat($_);
is $s-> backgroundRepeat, $_, "background-repeat value: \L$_"
}
$s-> backgroundRepeat('no-repeat');
for(qw "top 5") {
$s-> backgroundRepeat($_);
is $s-> backgroundRepeat, 'no-repeat', "invalid bg-repeat value: $_";
}
use tests 23; # background
{
my $props = sub {
return join ",", map $s->getPropertyValue("background-$_"),
qw(color image repeat attachment position)
};
$s->background('white');
is $s->background, 'white', 'background: colour';
is &$props, 'white,none,repeat,scroll,0% 0%',
'other sub-properties after setting background to colour';
is # bug fixed in 0.09, that only occurred in 5.10.0 [RT #54809]
$s->getPropertyCSSValue('background-color')->cssValueType,
1, # CSS_PRIMITIVE_VALUE
'value types of named subprops of shorthand props after sh. assignment';
$s->background('url(foo)');
is $s->background, 'url(foo)', 'background: url';
is &$props, 'transparent,url(foo),repeat,scroll,0% 0%',
'other sub-properties after setting background to url';
$s->background('no-repeat');
is $s->background, 'no-repeat', 'background: repeat';
is &$props, 'transparent,none,no-repeat,scroll,0% 0%',
'other sub-properties after setting background to repeat';
$s->background('fixed');
is $s->background, 'fixed', 'background: attachment';
is &$props, 'transparent,none,repeat,fixed,0% 0%',
'other sub-properties after setting background to attachment';
$s->background('top');
is $s->background, 'top', 'background: position (single keyword)';
is &$props, 'transparent,none,repeat,scroll,top',
'other sub-properties after setting background to position (single)';
$s->background('top left');
is $s->background, 'top left', 'background: position (two words)';
is &$props, 'transparent,none,repeat,scroll,top left',
'other sub-properties after setting background to position';
$s->background('red url("foo") no-repeat center center fixed');
is $s->background, 'red url("foo") no-repeat fixed center center',
'background with five values';
is &$props, 'red,url("foo"),no-repeat,fixed,center center',
'bg subprops after setting all at once';
$s->background('bottom scroll repeat-y none #00f');
is $s->background, '#00f repeat-y bottom',
'background with five values in reverse order';
is &$props, '#00f,none,repeat-y,scroll,bottom',
'bg subprops after setting backwards';
$s->background('');
is $s->background, '', 'setting background to nothing ...';
is &$props, ',,,,', ' ... resets all its sub-properties';
$s->background('blue');
$s->backgroundAttachment("");
is $s->background, '',
'background is blank if not all sub-properties are specified';
$s->background('transparent none repeat scroll 0% 0%');
is $s->background, 'none',
'background is none when all sub-properties are set to initial values';
}
$s->background('red');
$s->background("top red left");
is $s->background, 'red', "invalid background value: top red left";
$s->background("0");
is $s->background, "0", 'setting background to 0';
use tests 3; # border-collapse
for(qw 'collapse separate') {
$s->borderCollapse($_);
is $s->borderCollapse, $_, "border-collapse value: \L$_"
}
$s->borderCollapse('collapse');
$s->borderCollapse('no-repeat');
is $s->borderCollapse, 'collapse', "invalid border-claps val: no-repeat";
use tests 15; # border-color
{
my $props = sub {
return join ",", map $s->getPropertyValue("border-$_-color"),
qw(top right bottom left)
};
$s->borderColor('red');
is $s->borderColor, 'red', 'setting border-color to one value';
is &$props, 'red,red,red,red',
'result of setting border-color to one value';
$s->borderColor('red green');
is $s->borderColor, 'red green', 'setting border-color to two values';
is &$props, 'red,green,red,green',
'result of setting border-color to two values';
$s->borderColor('red green blue');
is $s->borderColor, 'red green blue',
'setting border-color to three values';
is &$props, 'red,green,blue,green',
'result of setting border-color to three values';
$s->borderColor('red green blue #f0f');
is $s->borderColor, 'red green blue #f0f',
'setting border-color to fourvalues';
is &$props, 'red,green,blue,#f0f',
'result of setting border-color to four values';
$s->borderColor('red red blue #f0f');
is $s->borderColor, 'red red blue #f0f',
'setting border-color to four values, the 1st 2 the same';
is &$props, 'red,red,blue,#f0f',
'result of setting border-color to four values, the 1st 2 the same';
$s->borderColor('rgb(255, 0, 0) rgb(0, 255, 0) rgb(0, 0, 255) rgb(0, 0, 0)');
is $s->borderColor, 'rgb(255, 0, 0) rgb(0, 255, 0) rgb(0, 0, 255) rgb(0, 0, 0)', # bug in 0.08 (fixed in 0.09)
'setting border-color to four rgb() values'; # that only affected
# cygwin perl
$s->borderColor('');
is $s->borderColor, '', 'setting border-color to nothing ...';
is &$props, ',,,', ' ... resets all its sub-properties';
$s->borderColor('blue');
$s->borderTopColor("");
is $s->borderColor, '',
'borderColor is blank if not all sub-properties are specified';
( run in 1.060 second using v1.01-cache-2.11-cpan-39bf76dae61 )