File: 59big.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 (130 lines) | stat: -rw-r--r-- 2,756 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
#!/usr/bin/env perl
# test use of big math

use warnings;
use strict;

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

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

use Test::More;

BEGIN {
   eval 'require Math::BigInt';
   if($@)
   {   plan skip_all => "Math::BigInt not installed";
   }

   plan tests => 66;
}

# Will fail when perl's longs get larger than 64bit
my $some_big1 = "12432156239876121237";
my $some_big2 = "243587092790745290879";

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

<simpleType name="t1">
  <restriction base="integer" />
</simpleType>

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

<simpleType name="t2">
  <restriction base="integer">
    <minInclusive value="40" />
    <maxInclusive value="$some_big1" />
  </restriction>
</simpleType>

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

<element name="test3">
  <complexType>
    <sequence>
      <element name="t3a" type="integer" default="$some_big2" />
      <element name="t3b" type="int"     default="11" />
    </sequence>
  </complexType>
</element>

<element name="test4">
  <complexType>
    <sequence>
      <element name="t4" type="integer" fixed="$some_big2" />
    </sequence>
  </complexType>
</element>

</schema>
__SCHEMA__

ok(defined $schema);

set_compile_defaults
    elements_qualified => 'NONE'
  , sloppy_integers    => 0;

##
### Integers
##

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

test_rw($schema, "test1" => <<__XML, Math::BigInt->new($some_big1));
<test1>$some_big1</test1>
__XML

test_rw($schema, "test2" => <<__XML, 42);
<test2>42</test2>
__XML

test_rw($schema, "test2" => <<__XML, Math::BigInt->new($some_big1));
<test2>$some_big1</test2>
__XML

# limit to huge maxInclusive

my $error = error_r($schema, test2 => <<__XML);
<test2>$some_big2</test2>
__XML

is($error, 'too large inclusive 243587092790745290879, max 12432156239876121237 at {http://test-types}test2#facet');

$error = error_w($schema, test2 => Math::BigInt->new($some_big2));
is($error, 'too large inclusive 243587092790745290879, max 12432156239876121237 at {http://test-types}test2#facet');

#
## Big defaults
#

my %t31 = (t3a => Math::BigInt->new($some_big1), t3b => 13);
test_rw($schema, "test3" => <<__XML, \%t31);
<test3><t3a>$some_big1</t3a><t3b>13</t3b></test3>
__XML

my %t34 = (t3a => Math::BigInt->new($some_big2), t3b => 11);
test_rw($schema, test3 => <<__XML, \%t34, <<__XML, {t3b => 11});
<test3 />
__XML
<test3><t3b>11</t3b></test3>
__XML

#
## Big fixed
#

my $bi4 = Math::BigInt->new($some_big2);
test_rw($schema, test4 => <<__XML, {t4 => $bi4}, <<__XML, {t4 => $bi4});
<test4><t4>$some_big2</t4></test4>
__XML
<test4><t4>$some_big2</t4></test4>
__XML