File: 20spec.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 (70 lines) | stat: -rw-r--r-- 1,884 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
#!/usr/bin/env perl

use warnings;
use strict;

use File::Spec;

use lib 'lib', 't';
use TestTools;
use XML::Compile::Schema;
use XML::Compile::Tester;

use Test::More tests => 22;

our $xmlfile = XML::Compile->findSchemaFile('2001-XMLSchema.xsd');

ok(-r $xmlfile,  'find demo file');

my $parser = XML::LibXML->new;
my $doc    = $parser->parse_file($xmlfile);
ok(defined $doc, 'parsing schema');
isa_ok($doc, 'XML::LibXML::Document');

my $defs  = XML::Compile::Schema->new($doc);
ok(defined $defs);

my $namespaces  = $defs->namespaces;
isa_ok($namespaces, 'XML::Compile::Schema::NameSpaces');

my @ns      = $namespaces->list;
cmp_ok(scalar(@ns), '==', 1, 'one target namespace');
my $ns = shift @ns;
is($ns, $SchemaNS);

my @schemas = $namespaces->namespace($ns);
ok(scalar(@schemas), 'found ns');

@schemas
   or die "no schemas, so no use to continue";

cmp_ok(scalar(@schemas), '==', 1, "one schema");
my $schema = $schemas[0];

my $list = '';
open OUT, '>', \$list or die $!;
$_->printIndex(\*OUT) for @schemas;
close OUT;
#warn $list;

my @types   = split /\n/, $list;
is(shift(@types), "namespace: $SchemaNS");
is(shift(@types), "   source: XML::LibXML::Document");
cmp_ok(scalar(@types), '==', 150);

my $random = (sort @types)[42];
is($random, '    derivationControl');

cmp_ok(scalar($schema->simpleTypes),     '==', 55);
cmp_ok(scalar($schema->complexTypes),    '==', 35);
cmp_ok(scalar($schema->groups),          '==', 12);
cmp_ok(scalar($schema->attributeGroups), '==',  2);
cmp_ok(scalar($schema->elements),        '==', 41);
cmp_ok(scalar($schema->attributes),      '==',  0);
#cmp_ok(scalar($schema->notations),      '==',  2);

my $testtype = '{http://www.w3.org/2001/XMLSchema}derivationControl';
my $lookup = $schema->find(simpleType => $testtype);
ok(defined $lookup, 'found simpleType');
is(ref $lookup, 'HASH');
ok(!$schema->find(complexType => $testtype));