1use strict; 2use warnings; 3 4use Test::More tests => 22; 5 6use HTML::FormFu::Util qw( 7 literal 8 remove_xml_attribute 9 xml_escape 10); 11 12{ 13 14 # remove literal from literal 15 my %attr = ( key => literal("<foo <bar <foo <bar <foo") ); 16 17 is( xml_escape( \%attr )->{key}, "<foo <bar <foo <bar <foo" ); 18 19 remove_xml_attribute( \%attr, "key", literal "<foo" ); 20 21 is( xml_escape( \%attr )->{key}, "<bar <foo <bar <foo" ); 22 23 remove_xml_attribute( \%attr, "key", literal "<foo" ); 24 25 is( xml_escape( \%attr )->{key}, "<bar <bar <foo" ); 26 27 remove_xml_attribute( \%attr, "key", literal "<foo" ); 28 29 is( xml_escape( \%attr )->{key}, "<bar <bar" ); 30 31 remove_xml_attribute( \%attr, "key", literal "<bar" ); 32 33 is( xml_escape( \%attr )->{key}, "<bar" ); 34 35 remove_xml_attribute( \%attr, "key", literal "<bar" ); 36 37 is( xml_escape( \%attr )->{key}, "" ); 38} 39 40{ 41 42 # remove string from literal 43 my %attr = ( key => literal("<foo <bar <foo <bar <foo") ); 44 45 is( xml_escape( \%attr )->{key}, 46 "<foo <bar <foo <bar <foo" ); 47 48 remove_xml_attribute( \%attr, "key", "<foo" ); 49 50 is( xml_escape( \%attr )->{key}, "<bar <foo <bar <foo" ); 51 52 remove_xml_attribute( \%attr, "key", "<foo" ); 53 54 is( xml_escape( \%attr )->{key}, "<bar <bar <foo" ); 55 56 remove_xml_attribute( \%attr, "key", "<foo" ); 57 58 is( xml_escape( \%attr )->{key}, "<bar <bar" ); 59 60 remove_xml_attribute( \%attr, "key", "<bar" ); 61 62 is( xml_escape( \%attr )->{key}, "<bar" ); 63 64 remove_xml_attribute( \%attr, "key", "<bar" ); 65 66 is( xml_escape( \%attr )->{key}, "" ); 67} 68 69{ 70 71 # remove string from string 72 my %attr = ( key => "<foo <bar <foo <bar <foo" ); 73 74 is( xml_escape( \%attr )->{key}, 75 "<foo <bar <foo <bar <foo" ); 76 77 remove_xml_attribute( \%attr, "key", "<foo" ); 78 79 is( xml_escape( \%attr )->{key}, "<bar <foo <bar <foo" ); 80 81 remove_xml_attribute( \%attr, "key", "<foo" ); 82 83 is( xml_escape( \%attr )->{key}, "<bar <bar <foo" ); 84 85 remove_xml_attribute( \%attr, "key", "<foo" ); 86 87 is( xml_escape( \%attr )->{key}, "<bar <bar" ); 88} 89 90{ 91 92 # remove literal from string 93 my %attr = ( key => "<foo <bar <foo <bar <foo" ); 94 95 is( xml_escape( \%attr )->{key}, 96 "<foo <bar <foo <bar <foo" ); 97 98 remove_xml_attribute( \%attr, "key", literal "<foo" ); 99 100 is( xml_escape( \%attr )->{key}, "<bar <foo <bar <foo" ); 101 102 remove_xml_attribute( \%attr, "key", literal "<foo" ); 103 104 is( xml_escape( \%attr )->{key}, "<bar <bar <foo" ); 105 106 remove_xml_attribute( \%attr, "key", literal "<foo" ); 107 108 is( xml_escape( \%attr )->{key}, "<bar <bar" ); 109 110 # ... remove a string 111 remove_xml_attribute( \%attr, "key", '<bar' ); 112 113 is( xml_escape( \%attr )->{key}, "<bar" ); 114} 115 116{ 117 118 # doesn't exist 119 my %attr = ( key => "foo" ); 120 121 remove_xml_attribute( \%attr, "NOT EXIST", 'bar' ); 122 123 is_deeply( \%attr, { key => "foo", }, "didn't change attributes", ); 124} 125