~ubuntu-branches/ubuntu/saucy/libhtml-stripscripts-perl/saucy

« back to all changes in this revision

Viewing changes to t/40bodytext.t

  • Committer: Bazaar Package Importer
  • Author(s): Tim Retout
  • Date: 2008-08-07 17:21:30 UTC
  • Revision ID: james.westby@ubuntu.com-20080807172130-3l9o4bwl9ftodfqh
Tags: upstream-1.04
ImportĀ upstreamĀ versionĀ 1.04

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
use strict;
 
3
use vars qw(@tests);
 
4
 
 
5
BEGIN {
 
6
    $^W = 1;
 
7
 
 
8
    @tests = (
 
9
      [ '',           ''            ],
 
10
      [ ''',     '''       ],
 
11
      [ '&',  '&'   ],
 
12
      [ '&',  '&'   ],
 
13
      [ '&*',         '&*'      ],
 
14
      [ '穩',   '穩'    ],
 
15
      [ 'ő',   'ő'      ],
 
16
      [ '',   ''    ],
 
17
      [ '',   ''    ],
 
18
      [ '', ''    ],
 
19
      [ '', ''    ],
 
20
      [ '&foo;',      '&foo;'       ],
 
21
      [ '&Foo3;',     '&Foo3;'      ],
 
22
      [ "\0",         ' '           ],
 
23
    );
 
24
 
 
25
    foreach my $pair (
 
26
      ['<','&lt;'],
 
27
      ['>','&gt;'],
 
28
      ['&','&amp;'],
 
29
      ['"','&quot;'],
 
30
      ["'",'&#39;'],
 
31
      ['a','a'],
 
32
    ) {
 
33
        my ($in, $out) = @$pair;
 
34
 
 
35
        push @tests, [ $in, $out ];
 
36
        push @tests, [ $out, $out ];
 
37
 
 
38
        my $dec = ord $in;
 
39
        push @tests, [ "&#$dec;", $out ];
 
40
        push @tests, [ "&#0$dec;", $out ];
 
41
        push @tests, [ "&#000$dec;", $out ];
 
42
 
 
43
        my $hex = sprintf '%x', $dec;
 
44
        push @tests, [ "&#x$hex;", $out ];
 
45
        push @tests, [ "&#X$hex;", $out ];
 
46
        push @tests, [ "&#x0$hex;", $out ];
 
47
        push @tests, [ "&#X0$hex;", $out ];
 
48
        push @tests, [ "&#x000$hex;", $out ];
 
49
        push @tests, [ "&#X000$hex;", $out ];
 
50
 
 
51
        if ($hex =~ /[a-f]/) {
 
52
            $hex = uc $hex;
 
53
            push @tests, [ "&#x$hex;", $out ];
 
54
            push @tests, [ "&#X$hex;", $out ];
 
55
            push @tests, [ "&#x0$hex;", $out ];
 
56
            push @tests, [ "&#X0$hex;", $out ];
 
57
            push @tests, [ "&#x000$hex;", $out ];
 
58
            push @tests, [ "&#X000$hex;", $out ];
 
59
        }
 
60
    }
 
61
                    
 
62
}
 
63
 
 
64
use Test::More tests => 4 * scalar(@tests);
 
65
 
 
66
use HTML::StripScripts;
 
67
my $f = HTML::StripScripts->new;
 
68
 
 
69
foreach my $test (@tests) {
 
70
    my ($in, $out) = @$test;
 
71
 
 
72
    $f->input_start_document;
 
73
    $f->input_text($in);
 
74
    $f->input_end_document;
 
75
    is( $f->filtered_document, $out, "text input [$in]" );
 
76
 
 
77
    $f->input_start_document;
 
78
    $f->input_text("=$in=");
 
79
    $f->input_end_document;
 
80
    is( $f->filtered_document, "=$out=", "text input [=$in=]" );
 
81
 
 
82
    my $esc = $in;
 
83
    $esc =~ s/"/&quot;/g;
 
84
 
 
85
    $f->input_start_document;
 
86
    $f->input_start(qq{<img alt="$esc">});
 
87
    $f->input_end_document;
 
88
    is( $f->filtered_document, qq{<img alt="$out" />}, "img alt input [$in]" );
 
89
 
 
90
    $f->input_start_document;
 
91
    $f->input_start(qq{<img alt="=$esc=">});
 
92
    $f->input_end_document;
 
93
    is( $f->filtered_document, qq{<img alt="=$out=" />}, "img alt input [=$in=]" );
 
94
}
 
95