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
|
#!/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 => 143;
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" />
<simpleType name="t5">
<union memberTypes="int">
<simpleType>
<restriction base="string">
<enumeration value="NIL"/>
</restriction>
</simpleType>
</union>
</simpleType>
<element name="test5">
<simpleType>
<list itemType="me:t5"/>
</simpleType>
</element>
<element name="test5b" type="me:t5" />
</schema>
__SCHEMA__
ok(defined $schema);
my $error;
### test1
test_rw($schema, test1 => <<__XML, 1 );
<test1>1</test1>
__XML
test_rw($schema, test1 => <<__XML, 0 );
<test1>0</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');
### test5
test_rw($schema, test5 => '<test5>1 2 3 4</test5>', [1..4]);
test_rw($schema, test5 => '<test5>3 NIL NIL 7</test5>', [3,'NIL','NIL',7]);
$error = error_r($schema, test5 => '<test5>A 42</test5>');
is($error, "no match for `A' in union at {http://test-types}test5#union");
test_rw($schema, test5b => '<test5b>0</test5b>', 0);
test_rw($schema, test5 => '<test5>0</test5>', [0]);
test_rw($schema, test5 => '<test5>0 0</test5>', [0, 0]);
|