| 1 | |
| 2 | use strictscip-perl cpan XML-Hash-XS 0.64 strict/; |
| 3 | use warningsscip-perl cpan XML-Hash-XS 0.64 warnings/; |
| 4 | |
| 5 | use Test::Morescip-perl cpan XML-Hash-XS 0.64 Test/More/ tests => 15; |
| 6 | |
| 7 | use XML::Hash::XSscip-perl cpan XML-Hash-XS 0.64 XML/Hash/XS/ 'hash2xml'; |
| 8 | |
| 9 | $XML::Hash::XS::methodscip-perl cpan XML-Hash-XS 0.64 XML/Hash/XS/$method. = 'LX'; |
| 10 | $XML::Hash::XS::trimscip-perl cpan XML-Hash-XS 0.64 XML/Hash/XS/$trim. = 1; |
| 11 | |
| 12 | our $xml_declscip-perl cpan XML-Hash-XS 0.64 main/$xml_decl. = qq{<?xml version="1.0" encoding="utf-8"?>\n}; |
| 13 | |
| 14 | { |
| 15 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 16 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { '#text' => ' zzzz ' } } ), |
| 17 | qq{$xml_decl<root>zzzz</root>}, |
| 18 | 'text', |
| 19 | ; |
| 20 | } |
| 21 | { |
| 22 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 23 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { sub => 'test' } } ), |
| 24 | qq{$xml_decl<root><sub>test</sub></root>}, |
| 25 | 'node', |
| 26 | ; |
| 27 | } |
| 28 | { |
| 29 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 30 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { -attr => "test < > & \" \t \n \r end" } } ), |
| 31 | qq{$xml_decl<root attr="test < > & " 	 end"></root>}, |
| 32 | 'attr', |
| 33 | ; |
| 34 | } |
| 35 | { |
| 36 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 37 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { _attr => "test" } }, attr => '_' ), |
| 38 | qq{$xml_decl<root attr="test"></root>}, |
| 39 | 'attr _', |
| 40 | ; |
| 41 | } |
| 42 | { |
| 43 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 44 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { '~' => "zzzz < > & \r end" } }, text => '~' ), |
| 45 | qq{$xml_decl<root>zzzz < > & end</root>}, |
| 46 | 'text ~', |
| 47 | ; |
| 48 | } |
| 49 | { |
| 50 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 51 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => " \t\ntest" }, trim => 1 ), |
| 52 | qq{$xml_decl<root>test</root>}, |
| 53 | 'trim 1', |
| 54 | ; |
| 55 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 56 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => " \t\ntest" }, trim => 0 ), |
| 57 | qq{$xml_decl<root> \t\ntest</root>}, |
| 58 | 'trim 0', |
| 59 | ; |
| 60 | } |
| 61 | { |
| 62 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 63 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { sub => { '@' => "cdata < > & \" \t \n \r end" } } }, cdata => '@' ), |
| 64 | qq{$xml_decl<root><sub><![CDATA[cdata < > & \" \t \n \r end]]></sub></root>}, |
| 65 | 'cdata @', |
| 66 | ; |
| 67 | } |
| 68 | { |
| 69 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 70 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { sub => { '/' => "comment < > & \" \t \n \r end" } } },comm => '/' ), |
| 71 | qq{$xml_decl<root><sub><!--comment < > & \" \t \n \r end--></sub></root>}, |
| 72 | 'comm /', |
| 73 | ; |
| 74 | } |
| 75 | { |
| 76 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 77 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { -attr => undef } } ), |
| 78 | qq{$xml_decl<root attr=""></root>}, |
| 79 | 'empty attr', |
| 80 | ; |
| 81 | } |
| 82 | { |
| 83 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 84 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { '#cdata' => undef } }, cdata => '#cdata' ), |
| 85 | qq{$xml_decl<root></root>}, |
| 86 | 'empty cdata', |
| 87 | ; |
| 88 | } |
| 89 | { |
| 90 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 91 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { '/' => undef } }, comm => '/' ), |
| 92 | qq{$xml_decl<root><!----></root>}, |
| 93 | 'empty comment', |
| 94 | ; |
| 95 | } |
| 96 | { |
| 97 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 98 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { x=>undef } } ), |
| 99 | qq{$xml_decl<root><x/></root>}, |
| 100 | 'empty tag', |
| 101 | ; |
| 102 | } |
| 103 | { |
| 104 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 105 | hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { item => [1, 2, 3, { -attr => 4, node => 5 }, [6, 7] ] } } ), |
| 106 | qq{$xml_decl<root><item>1</item><item>2</item><item>3</item><item attr="4"><node>5</node></item><item><item>6</item><item>7</item></item></root>}, |
| 107 | 'array', |
| 108 | ; |
| 109 | } |
| 110 | SKIP: { |
| 111 | my $data; |
| 112 | eval { $data = hash2xmlscip-perl cpan XML-Hash-XS 0.64 main/hash2xml().( { root => { test => "Тест" } }, encoding => 'cp1251' ) }; |
| 113 | my $err = $@scip-perl cpan XML-Hash-XS 0.64 main/`$@`.; |
| 114 | chompscip-perl cpan XML-Hash-XS 0.64 main/chomp(). $err; |
| 115 | skipscip-perl cpan XML-Hash-XS 0.64 main/skip(). $err, 1 if $err; |
| 116 | isscip-perl cpan XML-Hash-XS 0.64 main/is(). |
| 117 | $data, |
| 118 | qq{<?xml version="1.0" encoding="cp1251"?>\n<root><test>\322\345\361\362</test></root>}, |
| 119 | 'encoding support', |
| 120 | ; |
| 121 | } |