1use strict;
2use warnings;
3use lib qw( ./lib ../lib );
4
5use Data::Dumper;
6
7use Test::More;
8plan(tests => 5);
9
10use_ok('CSS::Inliner::Parser');
11
12#aggregate all our warnings, this test is specifically to determine how errors/warns are handled
13my @warnings = ();
14BEGIN { $SIG{'__WARN__'} = sub { push @warnings, $_[0] } }
15
16my $css = <<END;
17.foo {
18	color?: red;
19}
20END
21
22#test to ensure that fatal errors are in fact fatal
23my $fatal = CSS::Inliner::Parser->new({ warns_as_errors => 1 });
24
25eval {
26  $fatal->read({ css => $css });
27};
28
29ok($@ =~ /^Invalid or unexpected property/);
30
31@warnings = (); # clear all preceding warnings and start over
32
33#test to ensure that when fatals are disabled that we only get warnings
34my $suppressed = CSS::Inliner::Parser->new();
35
36eval {
37  $suppressed->read({ css => $css });
38};
39
40@warnings = @{$suppressed->content_warnings()};
41
42ok(scalar @warnings == 1);
43ok($warnings[0] =~ /^Invalid or unexpected property/);
44
45#test to ensure that errors are not thrown by default
46my $fatal = CSS::Inliner::Parser->new();
47
48eval {
49  $fatal->read({ css => $css });
50};
51
52ok($@ eq '');
53