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
|
use strict;
use warnings;
use Test::More;
use RDF::aREF::Decoder;
use Scalar::Util qw(reftype);
sub check_errors(@) {
my $errors = pop;
my %options = @_;
my $msg = delete $options{msg};
my $decoder = RDF::aREF::Decoder->new( complain => 2, %options );
local $Test::Builder::Level = $Test::Builder::Level + 1;
while (@$errors) {
my $aref = shift @$errors;
eval { $decoder->decode( $aref ) };
if (@$errors and reftype $errors->[0] eq reftype qr//) {
my $expect = shift @$errors;
like($@, $expect, ($msg // $expect));
} else {
ok $@, $msg // '';
}
}
}
check_errors [
{ _ns => [] },
=> qr{^namespace map must be map or string},
# invalid subjects
{ [] => { a => 'foaf:Person' } }
=> qr{^invalid subject: ARRAY\(},
{ '<x:subject>' => { a => 'foaf:Person' } }
=> qr{^invalid subject},
# invalid predicates
{ 'x:subject' => { \"" => "" } }
=> qr{^invalid predicate IRI SCALAR\(},
# TODO: check different forms of same IRI
# invalid objects
{ 'x:subject' => { a => \"" } }
=> qr{^object must not be reference to SCALAR},
{ 'x:subject' => { a => [ \"" ] } }
=> qr{^object must not be reference to SCALAR},
{ _ns => { 1 => 'http://example.org/' },
'x:subject' => { a => 'foaf:Person' } }
=> qr{^invalid prefix: 1},
{ _ns => { x => 'foo' },
'x:subject' => { a => 'foaf:Person' } }
=> qr{^invalid namespace: foo}
];
check_errors strict => 1, msg => 'strict makes undef error',
[ { '<x:subj>' => { a => undef } } => qr{.} ];
check_errors strict => 1, null => '', msg => 'strict makes null value error',
[ { '' => { a => 'foaf_Person' } } ];
check_errors strict => 1, msg => 'empty string not null by default',
[ { '' => { a => 'foaf_Person' } } ];
done_testing;
|