[Bps-public-commit] r11967 - in HTML-RewriteAttributes: .

sartak at bestpractical.com sartak at bestpractical.com
Tue Apr 29 18:54:42 EDT 2008


Author: sartak
Date: Tue Apr 29 18:54:42 2008
New Revision: 11967

Added:
   HTML-RewriteAttributes/t/022-import-off.t
Modified:
   HTML-RewriteAttributes/   (props changed)

Log:
 r54673 at onn:  sartak | 2008-04-29 18:38:59 -0400
 Ensure that @imports are not rewritten without inline_imports


Added: HTML-RewriteAttributes/t/022-import-off.t
==============================================================================
--- (empty file)
+++ HTML-RewriteAttributes/t/022-import-off.t	Tue Apr 29 18:54:42 2008
@@ -0,0 +1,75 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use HTML::RewriteAttributes::Resources;
+use Test::More tests => 3;
+
+my $html = << 'END';
+<html>
+    <head>
+        <link type="text/css" href="foo.css" />
+        <style type="text/css">
+ at import "bar.css";
+        </style>
+        <link type="text/css" href="baz.css" />
+    </head>
+    <body>
+    </body>
+</html>
+END
+
+my %css = (
+    "foo.css"  => 'foo; @import "quux.css";',
+    "bar.css"  => 'bar; @import "quux.css";',
+    "baz.css"  => 'baz; @import "foo.css";',
+    "quux.css" => 'quux; @import "bar.css"; @import "quux.css";',
+);
+
+my @seen;
+my @seen_css;
+
+my $rewrote = HTML::RewriteAttributes::Resources->rewrite($html, sub {
+    my $uri = shift;
+    push @seen, $uri;
+    return $uri;
+}, inline_css => sub {
+    my $uri = shift;
+    push @seen_css, $uri;
+    return $css{$uri};
+});
+
+is(@seen, 0, "no ordinary resources seen");
+is_deeply(\@seen_css, [
+    "foo.css",
+    "baz.css",
+]);
+
+$rewrote =~ s/ +$//mg;
+$rewrote =~ s/^ +//mg;
+
+is($rewrote, << 'END', "rewrote the html correctly");
+<html>
+<head>
+
+<style type="text/css">
+<!--
+foo; @import "quux.css";
+-->
+</style>
+
+<style type="text/css">
+ at import "bar.css";
+</style>
+
+<style type="text/css">
+<!--
+baz; @import "foo.css";
+-->
+</style>
+
+</head>
+<body>
+</body>
+</html>
+END
+



More information about the Bps-public-commit mailing list