File: 45ctcext.t

package info (click to toggle)
libxml-compile-perl 1.64-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,304 kB
  • sloc: perl: 11,616; makefile: 7
file content (157 lines) | stat: -rw-r--r-- 3,180 bytes parent folder | download | duplicates (6)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env perl
# test complex type extensions

use warnings;
use strict;

use lib 'lib','t';
use TestTools;

use XML::Compile::Schema;
use XML::Compile::Tester;

use Test::More tests => 50;

set_compile_defaults
    elements_qualified => 'NONE';

my $schema   = XML::Compile::Schema->new( <<__SCHEMA__ );
<schema targetNamespace="$TestNS"
        xmlns="$SchemaNS"
        xmlns:me="$TestNS">

<complexType name="t1">
  <sequence>
    <element name="t1_a" type="int" />
    <element name="t1_b" type="int" />
  </sequence>
  <attribute name="a1_a" type="int" />
  <attribute name="a1_b" type="int" use="required" />
</complexType>

<complexType name="t2">
  <complexContent>
    <extension base="me:t1">
      <sequence>
        <element name="t2_a" type="int" />
      </sequence>
      <attribute name="a2_a" type="int" />
    </extension>
  </complexContent>
</complexType>

<element name="test1" type="me:t2" />

<element name="test3" type="me:t3" />
<complexType name="t3">
  <attribute name="a3_a" type="int" />
</complexType>

<element name="test4">
  <complexType>
    <complexContent>
      <extension base="me:t3">
        <sequence>
          <element name="e4_a" type="int" />
        </sequence>
        <attribute name="a4_a" type="int" />
      </extension>
    </complexContent>
  </complexType>
</element>

<element name="test5" type="me:t5" />
<complexType name="t5">
  <sequence>
    <element name="e5" minOccurs="0" maxOccurs="5" />
  </sequence>
</complexType>

<element name="test6">
  <complexType>
    <sequence>
      <element name="e6" minOccurs="0" maxOccurs="5" type="me:t5" />
    </sequence>
    <attribute name="a6" type="int" />
  </complexType>
</element>

</schema>
__SCHEMA__

ok(defined $schema);

my %t1 = (t1_a => 11, t1_b => 12, a1_a => 13, a1_b => 14, t2_a => 15, a2_a=>16);

test_rw($schema, "test1" => <<__XML, \%t1);
<test1 a1_a="13" a1_b="14" a2_a="16">
   <t1_a>11</t1_a>
   <t1_b>12</t1_b>
   <t2_a>15</t2_a>
</test1>
__XML

### no base block

test_rw($schema, test3 => <<__XML, {a3_a => 20});
<test3 a3_a="20"/>
__XML

test_rw($schema, test4 => <<__XML, {a3_a => 21, a4_a => 22, e4_a => 23});
<test4 a3_a="21" a4_a="22">
  <e4_a>23</e4_a>
</test4>
__XML

### nested repeats

my %t6 = ( e6 => [ { e5 => [ 30, 31 ] }
                 , { e5 => [ 32 ] }
                 , { }
                 ] );

test_rw($schema, test6 => <<__XML, \%t6);
<test6>
  <e6><e5>30</e5><e5>31</e5></e6>
  <e6><e5>32</e5></e6>
  <e6/>
</test6>
__XML

test_rw($schema, test6 => '<test6/>', {});

test_rw($schema, test6 => '<test6><e6/></test6>', {e6 => [ {} ]} );

# attempt to reproduce bug rt.cpan.org#79986, reported by Karen Etheridge
my $out = templ_perl $schema, "{$TestNS}test1", skip_header => 1;
is($out, <<__EXPECT, 'templ of extension');
# Describing complex x0:test1
#     {http://test-types}test1

# is a x0:t2
{ # is a xs:int
  # becomes an attribute
  a1_a => 42,

  # is a xs:int
  # attribute a1_b is required
  a1_b => 42,

  # is a xs:int
  # becomes an attribute
  a2_a => 42,

  # sequence of t1_a, t1_b

  # is a xs:int
  t1_a => 42,

  # is a xs:int
  t1_b => 42,

  # sequence of t2_a

  # is a xs:int
  t2_a => 42, }
__EXPECT