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
|
use strict;
use warnings;
use Test::More;
use RDF::aREF::Encoder;
sub test_encoder(@) {
my ($encoder, $method, @tests) = @_;
while (@tests) {
my $input = shift @tests;
my $expect = shift @tests;
local $Test::Builder::Level = $Test::Builder::Level + 1;
if ( ref $expect ) {
is_deeply $encoder->$method($input), $expect, $expect;
} else {
is $encoder->$method($input), $expect, $expect;
}
}
}
my $encoder = RDF::aREF::Encoder->new( ns => '20140910' );
test_encoder $encoder => 'qname',
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' => 'rdf_type',
'http://schema.org/Review' => 'schema_Review',
;
test_encoder $encoder => 'predicate',
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' => 'a',
'http://undefinednamespace.foo' => 'http://undefinednamespace.foo',
'http://purl.org/dc/terms/title' => 'dct_title',
;
test_encoder $encoder => 'uri',
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' => 'rdf_type',
'http://undefinednamespace.foo' => '<http://undefinednamespace.foo>'
;
test_encoder $encoder => 'object',
# RDF/JSON
{
type => 'resource',
value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
} => 'rdf_type',
{
type => 'literal',
value => 'hello, world!',
lang => 'en'
} => 'hello, world!@en',
{
type => 'literal',
value => '12',
datatype => 'http://www.w3.org/2001/XMLSchema#integer'
} => '12^xs_integer',
{
type => 'bnode',
value => '_:12',
} => '_:12',
# RDF::Trine
['URI','http://www.w3.org/1999/02/22-rdf-syntax-ns#type'] => 'rdf_type',
['URI','http://www.w3.org/1999/02/22-rdf-syntax-ns#type'] => 'rdf_type',
['BLANK', 0 ] => '_:0',
['hello, world!', 'en', undef ] => 'hello, world!@en',
['hello, world!' ] => 'hello, world!@',
[42, undef, 'http://www.w3.org/2001/XMLSchema#integer'] => '42^xs_integer',
;
test_encoder $encoder => 'literal',
'' => '@'
;
test_encoder $encoder => 'bnode',
abc => '_:abc'
;
$encoder = RDF::aREF::Encoder->new( ns => 0 );
is $encoder->predicate('http://purl.org/dc/terms/title'),
'http://purl.org/dc/terms/title', 'predicate (ns=0)';
is $encoder->qname('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
'rdf_type', 'qname (ns=0)';
is $encoder->literal( 42, undef, 'http://www.w3.org/2001/XMLSchema#integer'),
'42^xsd_integer', 'literal (ns=0)';
done_testing;
|