CSS-DOM

 view release on metacpan or  search on metacpan

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

		'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("")',
		'blank double-quoted, unterminated url';
	$style->name('url(');
	is $style->name, 'url()',
		'unterminated unquoted url, ending with \)';
	$style->name(q"url('\'");
	is $style->name, q"url('\'')",
		'unterminated single-quoted url, ending with \\\'';
	$style->name('url("\"');
	is $style->name, 'url("\"")',
		'unterminated double-quoted url, ending with \"';
	$style->name(q"url('foo'");
	is $style->name, q"url('foo')",
		'single-quoted url without )';
	$style->name('url("foo"');
	is $style->name, 'url("foo")',
		'double-quoted url without )';
	$style->name(q"url('foo' ");
	is $style->name, q"url('foo' )",
		'single-quoted url without ) but with ws';
	$style->name('url("foo" ');
	is $style->name, 'url("foo" )',
		'double-quoted url without ) but with ws';
}

# ~~~ unicode range
# Come to think of it, if we didn’t support this as a separate token,
# U+abcd-U+012a would be interpreted as
# ident [U], delim [+], ident [abcd], delim [-], dim [012a]
# which would still become a CSS_UNKNOWN value whose cssText value returned
# exactly the same. So a test for it would pass whether unirange were a
# token or not. (Or would it become a primitive with a type of CSS_CUSTOM?)

use tests 3; # spaces and comments
{
	my $style = CSS::DOM::Style::parse(
		"name/*fooo*/  :"
		." \t\r\n\f/*etet*/ /**oo**//*oo** * **/\n/*/** /*/"
		. 'value/*eeeee'
	);
	is $style->name, 'value', 'whitespace and comments';
	$style = CSS::DOM::Style::parse(
		"name:valu  /*eeeee "  
	);
	is $style->name, 'valu', 'another ws /**/ test';
	$style = CSS'DOM'Style'parse( "name: /*\n*/valu");
	is $style->name, 'valu', 'multiline comments';
}

# ~~~ function

use tests 6; # <!-- -->
{
	my $sheet = CSS'DOM'parse ' <!--{ name: value }--> @media print{}';
	is join('',map cssText$_,cssRules$sheet),
		"{ name: value }\n\@media print {\n}\n",
		'ignored <!-- -->';
	is CSS'DOM'parse"{}{name: <!-- value; n:v}" =>->
		cssRules->length,
	   1,
		'invalid <!--';
	ok $@, '$@ after invalid <!--';
	is CSS'DOM'parse"{}{name: --> value; n:v}" =>->
		cssRules->length,
	   1,
		'invalid -->';
	ok $@, '$@ after invalid -->';
	is CSS'DOM'Style'parse"name:'<!--value-->",->name,
		"'<!--value-->'", '<!-- --> in a string';
}

use tests 1; # miscellaneous tokens
{
	my $sheet = CSS'DOM'parse  '@foo ()[~=:,./+-]{[("\"';
	is $sheet->cssRules->[0]->cssText,
		'@foo ()[~=:,./+-]{[("\"")]}'. "\n",
		'miscellaneous tokens'
}



( run in 0.389 second using v1.01-cache-2.11-cpan-e93a5daba3e )