CSS-DOM

 view release on metacpan or  search on metacpan

t/parser-tokens.t  view on Meta::CPAN

use tests 370; # identifiers
for('_', 'a'..'z', 'A'.."Z", map(chr,0x80..0x100) ,"\x{2003}","\x{3000}"){
	my $style = CSS::DOM::Style::parse($_ . 
		"\\20\\10fFfff-_abcABC\\}\\7d\\7d \\7d\t\\7d\r\n\\7d\n"
		. "\\7d\r\\7d\f\xff\x{2003}\x{100}\\\t"
		. ": 65"
	);
	is $style->getPropertyValue(
		"$_ \x{10ffff}f-_abcABC}}}}}}}}\xff\x{2003}\x{100}\t"
	), 65, 'identifier beginning with ' . (ord()<127 ? $_ :"chr ".ord);

	$style = CSS::DOM::Style::parse("-$_" . 
		"\\20\\10fFfff-_abcABC\\}\\7d\\7d \\7d\t\\7d\r\n\\7d\n"
		. "\\7d\r\\7d\f\xff\x{2003}\x{100}\\\t"
		. ": 65"
	);
	is $style->getPropertyValue(
		"-$_ \x{10ffff}f-_abcABC}}}}}}}}\xff\x{2003}\x{100}\t"
	), 65, 'identifier beginning with -'. (ord()<127 ? $_ :"chr ".ord);
}
{
	my $style = CSS::DOM::Style::parse("--a: 65");
	is $style->cssText, '', 'identifier can\'t begin with --';
	$style = CSS'DOM'Style'parse"-0b:-0b";
	is $style->cssText, '', 'nor with -0';
}

use tests 8; # strings
{
	my $nasty_escaped_string =
		"\\20\\10fFfff-_abcABC\\}\\7d\\7d \\7d\t\\7d\r\n\\7d\n"
		. "\\7d\r\\7d\f\xff\x{2003}\x{100}\\\r\n\\\n\\\r\\\t\\\f"
		. q/\'\"/;
	my $expect =
		qq/ \x{10ffff}f-_abcABC}}}}}}}}\xff\x{2003}\x{100}\t'"/;
	my $rule = new CSS::DOM::Rule'Import; 

	$rule->cssText('@import ' . "'$nasty_escaped_string'");
	is $rule->href, $expect, "'...'";
	$rule->cssText('@import ' . qq'"$nasty_escaped_string"');
	is $rule->href, $expect, '"..."';
	$rule->cssText('@import ' . "'$nasty_escaped_string");
	is $rule->href, $expect, "'...";
	$rule->cssText('@import ' . qq'"$nasty_escaped_string');
	is $rule->href, $expect, '"...';
	$rule->cssText('@import ' . q"'\'");
	is $rule->href, "'", q"'\'";
	$rule->cssText('@import ' . q'"\"');
	is $rule->href, '"', '"\"';
	$rule->cssText('@import ' . q"'");
	is $rule->href, "", q"'";
	$rule->cssText('@import ' . q'"');
	is $rule->href, '', '"';
}


# ~~~ once both selectors mean something and getCSSPropertyValue is imple-
#     mented, we need #hash tests

# ~~~ numbers
# ~~~ percent
# ~~~ dimensions


use tests 23; # urls
{
	my $rule = new CSS'DOM'Rule::Import;

	$rule->cssText('@import url(!$#%&][\\\}|{*~foo/bar.gif)');
	is $rule->href, '!$#%&][\}|{*~foo/bar.gif', 'unquoted url';
	$rule->cssText('@import url(/*foo*/foo/bar.gif/*bar)');
	is $rule->href, '/*foo*/foo/bar.gif/*bar', 
		'unquoted url w/"comments"';
	$rule->cssText('@import url("\"\'foo")');
	is $rule->href, q/"'foo/, 'double-quoted url';
	$rule->cssText('@import url(\'\\\'"foo\')');
	is $rule->href, q/'"foo/, 'single-quoted url';
	$rule->cssText("\@import url(\n \t\f\rstuff   \r\n\t \f)");
	is $rule->href, "stuff",
		'unquoted url with ws';
	$rule->cssText("\@import url(\n \t\f\r'stuff'   \r\n\t \f)");
	is $rule->href, "stuff",
		'single-quoted url with ws';
	$rule->cssText(qq'\@import url(\n \t\f\r"stuff"   \r\n\t \f)');
	is $rule->href, "stuff",
		'double-quoted url with ws';
	$rule->cssText('@import '.
		"url(\x{2000}\\2000\r\n\\a\n\\20 0\\20\r\\20\f\\)\\z)"
	);
	is $rule->href, "\x{2000}\x{2000}\n 0  )z",
		'unquoted url with escapes';
	$rule->cssText('@import '.
		"url('\x{2000}\\2000\r\n\\a\n\\20 0\\20\r\\20\f\\)"
		."\\\r\n\\\n\\\r\\\t\\\f\\z')"
	);
	is $rule->href, "\x{2000}\x{2000}\n 0  )\tz",
		'single-quoted  url with escapes';
	$rule->cssText('@import '.
		"url(\"\x{2000}\\2000\r\n\\a\n\\20 0\\20\r\\20\f\\)"
		."\\\r\n\\\n\\\r\\\t\\\f\\z\")"
	);
	is $rule->href, "\x{2000}\x{2000}\n 0  )\tz",
		'double-quoted url with escapes';

	my $style = new CSS'DOM'Style;

	$style->name('url(foo');
	is $style->name, 'url(foo)', 'unquoted, unterminated url';
	$style->name('url(\'goo');
	is $style->name, 'url(\'goo\')',
		'single-quoted, unterminated url';
	$style->name('url("foo');
	is $style->name, 'url("foo")',
		'double-quoted, unterminated url';
	$style->name('url(');
	is $style->name, 'url()', 'blank unquoted, unterminated url';
	$style->name('url(\'');
	is $style->name, 'url(\'\')',
		'blank single-quoted, unterminated url';
	$style->name('url("');
	is $style->name, 'url("")',



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