File: 74qname.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 (100 lines) | stat: -rw-r--r-- 1,977 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
#!/usr/bin/env perl
# QName builtins are harder, because they need the node which is processed
# to lookup the name-space.

use warnings;
use strict;

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

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

use Test::More tests => 33;

set_compile_defaults
    elements_qualified => 'NONE';

my $NS2 = "http://test2/ns";

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

<element name="test1" type="QName" />

<element name="test2">
  <simpleType>
    <list itemType="QName" />
  </simpleType>
</element>

<element name="test3">
  <simpleType>
    <restriction base="QName" />
  </simpleType>
</element>

<element name="test4">
  <simpleType name="t1">
    <union>
      <simpleType>
        <restriction base="QName" />
      </simpleType>
      <simpleType>
        <restriction base="string">
          <enumeration value="unbounded" />
        </restriction>
      </simpleType>
    </union>
  </simpleType>
</element>


</schema>
__SCHEMA__

ok(defined $schema);

my %prefixes =
  ( $TestNS => { prefix => '', uri => $TestNS }
  , $NS2    => { prefix => 'two', uri => $NS2, used => 1 }
  );

set_compile_defaults
    include_namespaces => 1
  , prefixes => \%prefixes;

### QName direct

test_rw($schema, test1 => <<__TRY1, "{$NS2}aaa"); 
<test1 xmlns="$TestNS" xmlns:two="$NS2">two:aaa</test1>
__TRY1

### QName in LIST

$prefixes{$NS2}{used} = 1;
test_rw($schema, test2 => <<__TRY2, [ "{$NS2}aaa", "{$NS2}bbb" ]); 
<test2 xmlns="$TestNS" xmlns:two="$NS2">
  two:aaa
  two:bbb
</test2>
__TRY2

### QName extended

$prefixes{$NS2}{used} = 1;
test_rw($schema, test3 => <<__TRY3, "{$NS2}aaa"); 
<test3 xmlns="$TestNS" xmlns:two="$NS2">two:aaa</test3>
__TRY3

### QName union

$prefixes{$NS2}{used} = 1;
test_rw($schema, test4 => <<__TRY4, "{$NS2}aaa"); 
<test4 xmlns="$TestNS" xmlns:two="$NS2">two:aaa</test4>
__TRY4