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
|
#!/usr/bin/env perl
# simpleType list
use warnings;
use strict;
use lib 'lib','t';
use TestTools;
use XML::Compile::Schema;
use XML::Compile::Tester;
use Test::More tests => 124;
set_compile_defaults
elements_qualified => 'NONE';
my $schema = XML::Compile::Schema->new( <<__SCHEMA );
<schema targetNamespace="$TestNS"
xmlns="$SchemaNS"
xmlns:me="$TestNS">
<simpleType name="t1">
<list itemType="int" />
</simpleType>
<element name="test1" type="me:t1" />
<simpleType name="t2">
<list>
<simpleType>
<restriction base="int" />
</simpleType>
</list>
</simpleType>
<element name="test2" type="me:t2" />
<element name="test3">
<simpleType>
<restriction base="me:t2">
<enumeration value="1 2" />
<enumeration value="2 1" />
</restriction>
</simpleType>
</element>
<element name="test4">
<simpleType>
<restriction base="NMTOKENS">
<enumeration value="3 4" />
<enumeration value="5 6" />
</restriction>
</simpleType>
</element>
</schema>
__SCHEMA
ok(defined $schema);
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, [0, 0]);
<test1>0 0</test1>
__XML
test_rw($schema, test1 => <<__XML, [2, 3]);
<test1>2 3</test1>
__XML
test_rw($schema, test1 => <<__XML, [4, 5, 6]);
<test1> 4
5\t 6 </test1>
__XML
test_rw($schema, test2 => <<__XML, [1]);
<test2>1</test2>
__XML
test_rw($schema, test2 => <<__XML, [2, 3]);
<test2>2 3</test2>
__XML
test_rw($schema, test2 => <<__XML, [0, 0]);
<test2>0 0</test2>
__XML
test_rw($schema, test2 => <<__XML, [4, 5, 6]);
<test2> 4
5\t 6 </test2>
__XML
test_rw($schema, test2 => <<__XML, []);
<test2></test2>
__XML
# restriction on simple-list base
test_rw($schema, test3 => <<__XML, [1, 2]);
<test3>1 2</test3>
__XML
test_rw($schema, test3 => <<__XML, [2, 1]);
<test3>2 1</test3>
__XML
my $error = error_r($schema, test3 => '<test3>2 2</test3>');
is($error, "invalid enumerate `2 2' at {http://test-types}test3#facet");
$error = error_w($schema, test3 => [3, 3]);
is($error, "invalid enumerate `3 3' at {http://test-types}test3#facet");
# predefined
test_rw($schema, test4 => <<__XML, [3, 4]);
<test4>3 4</test4>
__XML
$error = error_w($schema, test4 => [3, 3]);
is($error, "invalid enumerate `3 3' at {http://test-types}test4#facet");
# element has attributes as well
my $w1 = writer_create($schema, "HASH param" => "{$TestNS}test1");
my $x1 = writer_test($w1, {_ => [7,8]});
compare_xml($x1->toString, <<'_XML');
<test1>7 8</test1>
_XML
|