File: namespaces.t

package info (click to toggle)
librdf-trine-node-literal-xml-perl 0.16-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 232 kB
  • sloc: perl: 1,511; makefile: 2
file content (117 lines) | stat: -rw-r--r-- 4,946 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
use Test::More tests => 29 ;
use Test::Exception;
use Test::NoWarnings;

use strict;
use warnings;


use_ok( 'RDF::Trine::Node::Literal::XML' );
use_ok( 'XML::LibXML' );

throws_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo>bar', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'RDF::Trine::Error', 'throws on invalid xml';

throws_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo>bar');
} 'RDF::Trine::Error', 'throws on invalid xml without optional arguments';


throws_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo>', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'RDF::Trine::Error', 'throws on invalid xml';



throws_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo/>', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'RDF::Trine::Error', 'throws on valid empty-element xml with undeclared ns prefix';

throws_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo/>' );
}  'RDF::Trine::Error', 'throws on valid empty-element xml without optional arguments with undeclared ns prefix';



throws_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo/>bar', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'RDF::Trine::Error', 'throws on element xml with content at the end with undeclared ns prefix';


throws_ok {
	my $l	= RDF::Trine::Node::Literal::XML->new( 'baz<ex:bar>baz</ex:bar><ex:foo/>', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'RDF::Trine::Error', 'throws on valid two-element with content xml with undeclared ns prefix';

lives_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo xmlns:ex="http://example.org/ns"/>', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'lives on valid empty-element xml';

lives_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo xmlns:ex="http://example.org/ns"/>' );
} 'lives on valid empty-element xml without optional arguments';



lives_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<ex:foo xmlns:ex="http://example.org/ns"/>bar', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'lives on element xml with content at the end';


lives_ok {
	my $l	= RDF::Trine::Node::Literal::XML->new( 'baz<ex:bar xmlns:ex="http://example.org/ns">baz</ex:bar><ex:foo xmlns:ex="http://example.org/ns"/>', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'lives on valid two-element with content xml';



{
	my $l	= RDF::Trine::Node::Literal::XML->new( '<ex:foo xmlns:ex="http://example.org/ns">bar</ex:foo>', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
	isa_ok( $l, 'RDF::Trine::Node::Literal::XML' );
	is( $l->literal_value, '<ex:foo xmlns:ex="http://example.org/ns">bar</ex:foo>', 'expected literal value' );
	is( $l->literal_datatype, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral', 'expected literal datatype' );
}



{
	my $el	= XML::LibXML::Element->new( 'a' );
	$el->setNamespace( 'http://example.org/ns' , 'ex');
	my $l	= RDF::Trine::Node::Literal::XML->new( $el );
	isa_ok( $l, 'RDF::Trine::Node::Literal::XML' );
	is( $l->literal_value, '<ex:a xmlns:ex="http://example.org/ns"/>', 'expected literal value' );
	is( $l->literal_datatype, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral', 'expected literal datatype' );
}

{
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_string( '<ex:root xmlns:ex="http://example.org/ns"><ex:bar>baz</ex:bar><ex:foo>dahut</ex:foo></ex:root>');
  my $nodes = $doc->findnodes('/ex:root/*');
  my $l	= RDF::Trine::Node::Literal::XML->new( $nodes );
  isa_ok( $l, 'RDF::Trine::Node::Literal::XML' );
  is( $l->literal_value, '<ex:bar xmlns:ex="http://example.org/ns">baz</ex:bar><ex:foo xmlns:ex="http://example.org/ns">dahut</ex:foo>', 'nodelist expected literal value' );
  my $el = $l->xml_element;
  isa_ok( $el, 'XML::LibXML::NodeList' );
}

{
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_string( '<ex:root xmlns:ex="http://example.org/ns"><ex:bar>baz</ex:bar><foo>dahut</foo></ex:root>');
  my $nodes = $doc->findnodes('/ex:root/*');
  my $l	= RDF::Trine::Node::Literal::XML->new( $nodes );
  isa_ok( $l, 'RDF::Trine::Node::Literal::XML' );
  is( $l->literal_value, '<ex:bar xmlns:ex="http://example.org/ns">baz</ex:bar><foo>dahut</foo>', 'nodelist expected literal value' );
  my $el = $l->xml_element;
  isa_ok( $el, 'XML::LibXML::NodeList' );
}

{
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_string( '<root xmlns="http://example.org/ns"><bar>baz</bar><foo>dahut</foo></root>');
  my $l	= RDF::Trine::Node::Literal::XML->new( $doc );
  isa_ok( $l, 'RDF::Trine::Node::Literal::XML' );
  is( $l->literal_value, '<root xmlns="http://example.org/ns"><bar>baz</bar><foo>dahut</foo></root>', 'document expected literal value, default namespace' );
  my $el = $l->xml_element;
  isa_ok( $el, 'XML::LibXML::Document' );
}