1use strict;
2use warnings;
3
4use Test::More tests => 7;
5
6use HTML::FormFu::Util qw(
7    literal
8    append_xml_attribute
9    xml_escape
10);
11
12{
13    my %attr = ( foo => literal "<bar" );
14
15    is( xml_escape( \%attr )->{foo}, "<bar" );
16
17    # literal + literal
18    append_xml_attribute( \%attr, "foo", literal ">baz" );
19
20    is( xml_escape( \%attr )->{foo}, "<bar >baz" );
21
22    # literal + string
23    append_xml_attribute( \%attr, "foo", "<boo" );
24
25    is( xml_escape( \%attr )->{foo}, "<bar >baz &lt;boo" );
26}
27
28{
29    my %attr = ( foo => "<bar" );
30
31    is( xml_escape( \%attr )->{foo}, "&lt;bar" );
32
33    # string + string
34    append_xml_attribute( \%attr, "foo", ">baz" );
35
36    is( xml_escape( \%attr )->{foo}, "&lt;bar &gt;baz" );
37
38    # string + literal
39    append_xml_attribute( \%attr, "foo", literal "<boo" );
40
41    is( xml_escape( \%attr )->{foo}, "&lt;bar &gt;baz <boo" );
42
43    # ... + string
44    append_xml_attribute( \%attr, "foo", '"bang' );
45
46    is( xml_escape( \%attr )->{foo}, "&lt;bar &gt;baz <boo &#34;bang" );
47}
48