CSS-DOM
view release on metacpan or search on metacpan
t/charset.t view on Meta::CPAN
#!/usr/bin/perl -T
use strict; use warnings; no warnings qw 'utf8 parenthesis';
our $tests;
BEGIN { ++$INC{'tests.pm'} }
sub tests'VERSION { $tests += pop };
use Test::More;
plan tests => $tests;
use utf8;
use CSS::DOM;
use tests 4; # options
like CSS::DOM::parse qq|\@charset "utf-8"; {font:'\xc3\xb0'}|
=>->cssRules->[1]->style->font,
qr/\xc3\xb0/, 'no decode/encoding_hint param assumes unicode';
like CSS::DOM::parse "{font:'\xc3\xb0'}",
decode => 1
=>->cssRules->[0]->cssText, qr/\xf0/,
'decode => 1 assumes utf-8 in the absence of encoding info';
like CSS::DOM::parse "{font:'\xc3\xb0'}",
encoding_hint => 'iso-8859-7'
=>->cssRules->[0]->cssText, qr/\x{393}\260/,
'encoding_hint implies decode => 1';
like CSS::DOM::parse "{font:'\xc3\xb0'}",
decode => 1, encoding_hint => 'iso-8859-7'
=>->cssRules->[0]->cssText,qr/\x{393}\260/,
'decode => 1 uses encoding_hint in the absence of bom or @charset';
use tests 18; # sniffing
for(
# ['test name',
# qq[stylesheet],
# rule_number_to_test => qr/.../],
['utf-8 bom and explicit charset',
qq[\xef\xbb\xbf\@charset "utf-8"; {font:'\xc3\xb0'}],
1 => qr/\xf0/],
['utf-8 bomb',
qq[\xef\xbb\xbf {font:'\xc3\xb0'}],
0 => qr/\xf0/],
['utf-16be bomb + @charset',
qq[\xfe\xff\0\@\0c\0h\0a\0r\0s\0e\0t\0 \0"\0u\0t\0f\0-\0001]
.qq[\0006\0"\0;\0 \0{\0f\0o\0n\0t\0:\0'\xab\xcd\0'\0}],
1 => qr/\x{abcd}/],
['apparent utf-16be with @charset',
qq[\0\@\0c\0h\0a\0r\0s\0e\0t\0 \0"\0u\0t\0f\0-\0001\0006\0"]
.qq[\0;\0 \0{\0f\0o\0n\0t\0:\0'\xab\xcd\0'\0}],
1 => qr/\x{abcd}/],
['utf-16le bomb + @charset',
qq[\xff\xfe\@\0c\0h\0a\0r\0s\0e\0t\0 \0"\0u\0t\0f\0-\0001]
.qq[\0006\0"\0;\0 \0{\0f\0o\0n\0t\0:\0'\0\xab\xcd'\0}\0],
1 => qr/\x{cdab}/],
['apparent utf-16le with @charset',
qq[\@\0c\0h\0a\0r\0s\0e\0t\0 \0"\0u\0t\0f\0-\0001\0006\0"\0]
.qq[;\0 \0{\0f\0o\0n\0t\0:\0'\0\xab\xcd'\0}\0],
1 => qr/\x{cdab}/],
['utf-32be bomb + @charset',
qq[\0\0\xfe\xff\0\0\0\@\0\0\0c\0\0\0h\0\0\0a\0\0\0r\0\0\0s]
.qq[\0\0\0e\0\0\0t\0\0\0 \0\0\0"\0\0\0u\0\0\0t\0\0\0f\0\0\0-]
.qq[\0\0\0003\0\0\0002\0\0\0"]
.qq[\0\0\0;\0\0\0 \0\0\0{\0\0\0f\0\0\0o\0\0\0n\0\0\0t\0\0\0:]
.qq[\0\0\0'\0\x10\xab\xcd\0\0\0'\0\0\0}],
1 => qr/\x{10abcd}/],
['apparent utf-32be with @charset',
qq[\0\0\0\@\0\0\0c\0\0\0h\0\0\0a\0\0\0r\0\0\0s]
.qq[\0\0\0e\0\0\0t\0\0\0 \0\0\0"\0\0\0u\0\0\0t\0\0\0f\0\0\0-]
.qq[\0\0\0003\0\0\0002\0\0\0"]
( run in 0.455 second using v1.01-cache-2.11-cpan-e93a5daba3e )