File: 50union.t

package info (click to toggle)
libxml-compile-perl 1.47-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,224 kB
  • ctags: 355
  • sloc: perl: 11,042; makefile: 2
file content (117 lines) | stat: -rw-r--r-- 2,541 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env perl
# simpleType union

use warnings;
use strict;

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

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

use Test::More tests => 91;

set_compile_defaults
    elements_qualified => 'NONE';

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

<simpleType name="t1">
  <union>
    <simpleType>
      <restriction base="int" />
    </simpleType>
    <simpleType>
      <restriction base="string">
        <enumeration value="unbounded" />
      </restriction>
    </simpleType>
  </union>
</simpleType>

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

<simpleType name="t2">
  <restriction base="string">
     <enumeration value="any" />
  </restriction>
</simpleType>

<simpleType name="t3">
  <union memberTypes="me:t2 int">
    <simpleType>
      <restriction base="string">
         <enumeration value="none" />
      </restriction>
    </simpleType>
  </union>
</simpleType>
<element name="test3" type="me:t3" />

<simpleType name="timestampType">
  <union memberTypes="date dateTime" />
</simpleType>
<element name="test4" type="me:timestampType" />

</schema>
__SCHEMA__

ok(defined $schema);
my $error;

### test1

test_rw($schema, test1 => <<__XML, 1 );
<test1>1</test1>
__XML

test_rw($schema, test1 => <<__XML, 'unbounded');
<test1>unbounded</test1>
__XML

$error = error_r($schema, test1 => <<__XML);
<test1>other</test1>
__XML
is($error, "no match for `other' in union at {http://test-types}test1#union");

$error = error_w($schema, test1 => 'other');
is($error, "no match for `other' in union at {http://test-types}test1#union");

### test3

test_rw($schema, test3 => <<__XML, 1 );
<test3>1</test3>
__XML

test_rw($schema, test3 => <<__XML, 'any');
<test3>any</test3>
__XML

test_rw($schema, test3 => <<__XML, 'none');
<test3>none</test3>
__XML

$error = error_r($schema, test3 => <<__XML);
<test3>other</test3>
__XML
is($error, "no match for `other' in union at {http://test-types}test3#union");

$error = error_w($schema, test3 => 'other');
is($error, "no match for `other' in union at {http://test-types}test3#union");

### test4

test_rw($schema, test4 => "<test4>2011-07-06</test4>", '2011-07-06');

test_rw($schema, test4 => "<test4>2011-07-06T10:06:24</test4>",
   '2011-07-06T10:06:24');

test_rw($schema, test4 => "<test4>2011-07-06T10:06:54Z</test4>",
   '2011-07-06T10:06:54Z');

test_rw($schema, test4 => "<test4>2011-07-06T10:10:32+02:00</test4>",
   '2011-07-06T10:10:32+02:00');