Debian Codegraph @

t/14-x2h_merge_text.t

raw
1 package main;
2 use strict;
3 use warnings;
4
5 use Test::More tests => 3;
6 use Data::Dumper;
7 $Data::Dumper::Indent = 0;
8 $Data::Dumper::Sortkeys = 1;
9
10 use XML::Hash::XS 'xml2hash';
11
12 our $xml_decl_utf8 = qq{<?xml version="1.0" encoding="utf-8"?>};
13
14 {
15 is
16 Dumper(xml2hash(<<"XML", force_array => 1, force_content => 1, merge_text => 1, keep_root => 1, trim => 1)),
17 <?xml version="1.0" encoding="utf-8"?>
18 <root>
19 <node1>123</node1>
20 <node3 attr1="attr1_content" subnode3="subnode30_content">
21 node3_content_1
22 <subnode3>
23 subnode31_content
24 </subnode3>
25 node3_content_2
26 <subnode3>
27 subnode32_content
28 <!-- comment -->
29 subnode32_content2
30 </subnode3>
31 <subnode3>
32 subnode33_content
33 </subnode3>
34 </node3>
35 </root>
36 XML
37 Dumper({
38 'root' => {
39 'node1' => [ { content => '123' } ],
40 'node3' => [
41 { 'attr1' => [ { content => 'attr1_content' } ],
42 'content' => ['node3_content_1', 'node3_content_2'],
43 'subnode3' => [
44 { content => 'subnode30_content' },
45 { content => 'subnode31_content' },
46 { content => 'subnode32_contentsubnode32_content2' },
47 { content => 'subnode33_content' },
48 ],
49 },
50 ],
51 },
52 }),
53 'use merge_text option',
54 ;
55 }
56
57 {
58 is
59 Dumper(xml2hash(<<"XML", merge_text => 1, keep_root => 1)),
60 <?xml version="1.0" encoding="utf-8"?>
61 <root>
62 <![CDATA[Hello,]]><![CDATA[ world!\n]]>
63 </root>
64 XML
65 Dumper({
66 'root' => "Hello, world!\n"
67 }),
68 'merge cdata',
69 ;
70 }
71
72 {
73 is
74 Dumper(xml2hash(<<"XML", merge_text => 1, keep_root => 1)),
75 <?xml version="1.0" encoding="utf-8"?>
76 <root>
77 <value><![CDATA[Hello,]]></value>
78 <value><![CDATA[ world!\n]]></value>
79 </root>
80 XML
81 Dumper({
82 'root' => {
83 'value' => ["Hello,", " world!\n"],
84 },
85 }),
86 'don`t merge text from different nodes',
87 ;
88 }