File: xmlliteral.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 (151 lines) | stat: -rw-r--r-- 5,298 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use Test::More tests => 37;
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( '<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( '<foo>bar');
} 'RDF::Trine::Error', 'throws on invalid xml without optional arguments';


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

lives_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'lives on empty literal';

lives_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( 'text', undef, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' );
} 'lives on plain text literal';


lives_ok {
	my $l		= RDF::Trine::Node::Literal::XML->new( '<foo/>', 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( '<foo/>' );
} 'lives on valid empty-element xml without optional arguments';



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

{
	my $l	= RDF::Trine::Node::Literal::XML->new( '<foo>bar</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, '<foo>bar</foo>', 'expected literal value' );
	is( $l->literal_datatype, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral', 'expected literal datatype' );
}

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


{
	my $el	= XML::LibXML::Element->new( 'a' );
	my $l	= RDF::Trine::Node::Literal::XML->new( $el );
	isa_ok( $l, 'RDF::Trine::Node::Literal::XML' );
	is( $l->literal_value, '<a/>', '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( '<root><bar>baz</bar><foo>dahut</foo></root>');
  my $nodes = $doc->findnodes('/root/*');
  my $l	= RDF::Trine::Node::Literal::XML->new( $nodes );
  isa_ok( $l, 'RDF::Trine::Node::Literal::XML' );
  is( $l->literal_value, '<bar>baz</bar><foo>dahut</foo>', 'nodelist expected literal value' );
  my $el = $l->xml_element;
  isa_ok( $el, 'XML::LibXML::NodeList' );
}


lives_ok {
	my $text = XML::LibXML::Text->new('text');
	my $l	= RDF::Trine::Node::Literal::XML->new( $text );
} 'lives on text node';


lives_ok { 
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_string( '<bar>baz</bar>');
  my $l	= RDF::Trine::Node::Literal::XML->new( $doc );
} 'lives on document node';


lives_ok { 
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_balanced_chunk( '<bar>baz</bar>');
  my $l	= RDF::Trine::Node::Literal::XML->new( $doc );
} 'lives on documentfragment node';

lives_ok { 
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_string( '<bar>baz</bar>');
  my $l	= RDF::Trine::Node::Literal::XML->new( $doc, 'tlh' );
} 'lives on document node with lang';


lives_ok { 
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_balanced_chunk( '<bar>baz</bar>');
  my $l	= RDF::Trine::Node::Literal::XML->new( $doc , 'tlh' );
} 'lives on documentfragment node with lang';


lives_ok { 
  my $node = XML::LibXML::CDATASection->new( '<cdata>' );
  my $l	= RDF::Trine::Node::Literal::XML->new( $node );
} 'lives on cdatasection';


lives_ok { 
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_string( '<root><bar>baz</bar><foo>dahut</foo></root>');
  my $nodes = $doc->findnodes('/root/*');
  my $l	= RDF::Trine::Node::Literal::XML->new( $nodes );
} 'lives on nodelist';

lives_ok { 
  my $parser = XML::LibXML->new();
  my $doc = $parser->parse_string( '<root><bar>baz</bar><foo>dahut</foo></root>');
  my $nodes = $doc->findnodes('/root/*');
  my $l	= RDF::Trine::Node::Literal::XML->new( $nodes, 'tlh' );
} 'lives on nodelist with lang';