File: 001-basic.t

package info (click to toggle)
libhtml-rewriteattributes-perl 0.05-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 216 kB
  • sloc: perl: 2,139; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env perl
use strict;
use warnings;
use HTML::RewriteAttributes;
use Test::More tests => 2;

my $html = << "END";
<html>
    <body>
        <img src="moose.jpg" />
        <img src="http://example.com/nethack.png">
        <p align="justified" style="color: red">
            hooray
        </p>
    </body>
</html>
END

my @seen;

my $rewrote = HTML::RewriteAttributes->rewrite($html, sub {
    my ($tag, $attr, $value) = @_;
    push @seen, [$tag, $attr, $value];

    return uc $value;
});

is_deeply(\@seen, [
    [img => src => "moose.jpg"],
    [img => src => "http://example.com/nethack.png"],
    [p => align => "justified"],
    [p => style => "color: red"],
]);

is($rewrote, << "END", "rewrote the html correctly");
<html>
    <body>
        <img src="MOOSE.JPG" />
        <img src="HTTP://EXAMPLE.COM/NETHACK.PNG">
        <p align="JUSTIFIED" style="COLOR: RED">
            hooray
        </p>
    </body>
</html>
END