File: remove_xml_attribute.t

package info (click to toggle)
libhtml-formfu-perl 2.05000-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,328 kB
  • ctags: 831
  • sloc: perl: 12,785; makefile: 9; sql: 5
file content (130 lines) | stat: -rw-r--r-- 3,120 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use strict;
use warnings;

use Test::More tests => 22;

use HTML::FormFu::Util qw(
    literal
    remove_xml_attribute
    xml_escape
);

{

    # remove literal from literal
    my %attr = ( key => literal("<foo <bar <foo <bar <foo") );

    is( xml_escape( \%attr )->{key}, "<foo <bar <foo <bar <foo" );

    remove_xml_attribute( \%attr, "key", literal "<foo" );

    is( xml_escape( \%attr )->{key}, "<bar <foo <bar <foo" );

    remove_xml_attribute( \%attr, "key", literal "<foo" );

    is( xml_escape( \%attr )->{key}, "<bar <bar <foo" );

    remove_xml_attribute( \%attr, "key", literal "<foo" );

    is( xml_escape( \%attr )->{key}, "<bar <bar" );

    remove_xml_attribute( \%attr, "key", literal "<bar" );

    is( xml_escape( \%attr )->{key}, "<bar" );

    remove_xml_attribute( \%attr, "key", literal "<bar" );

    is( xml_escape( \%attr )->{key}, "" );
}

{

    # remove string from literal
    my %attr = ( key => literal("&lt;foo &lt;bar &lt;foo &lt;bar &lt;foo") );

    is( xml_escape( \%attr )->{key},
        "&lt;foo &lt;bar &lt;foo &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", "<foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;foo &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", "<foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", "<foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;bar" );

    remove_xml_attribute( \%attr, "key", "<bar" );

    is( xml_escape( \%attr )->{key}, "&lt;bar" );

    remove_xml_attribute( \%attr, "key", "<bar" );

    is( xml_escape( \%attr )->{key}, "" );
}

{

    # remove string from string
    my %attr = ( key => "<foo <bar <foo <bar <foo" );

    is( xml_escape( \%attr )->{key},
        "&lt;foo &lt;bar &lt;foo &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", "<foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;foo &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", "<foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", "<foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;bar" );
}

{

    # remove literal from string
    my %attr = ( key => "<foo <bar <foo <bar <foo" );

    is( xml_escape( \%attr )->{key},
        "&lt;foo &lt;bar &lt;foo &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", literal "&lt;foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;foo &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", literal "&lt;foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;bar &lt;foo" );

    remove_xml_attribute( \%attr, "key", literal "&lt;foo" );

    is( xml_escape( \%attr )->{key}, "&lt;bar &lt;bar" );

    # ... remove a string
    remove_xml_attribute( \%attr, "key", '<bar' );

    is( xml_escape( \%attr )->{key}, "&lt;bar" );
}

{

    # doesn't exist
    my %attr = ( key => "foo" );

    remove_xml_attribute( \%attr, "NOT EXIST", 'bar' );

    is_deeply(
        \%attr,
        {
            key => "foo",
        },
        "didn't change attributes",
    );
}