Attean
view release on metacpan or search on metacpan
use v5.14;
use utf8;
use Data::Dumper;
use Test::Modern;
use Type::Tiny::Role;
use Attean::RDF;
my $XSD = "http://www.w3.org/2001/XMLSchema#";
is(iri('http://example.org/')->ntriples_string, '<http://example.org/>', 'IRI ntriples_string');
is(iri('http://example.org/âª')->ntriples_string, '<http://example.org/\u272A>', 'unicode IRI ntriples_string');
is(literal("ð¶\\\nâª")->ntriples_string, qq["ð¶\\\\\\nâª"], 'unicode literal ntriples_string');
is(literal('Eve')->ntriples_string, '"Eve"', 'literal ntriples_string');
is(langliteral('Eve', 'en')->ntriples_string, '"Eve"@en', 'lang-literal ntriples_string');
is(blank('eve')->ntriples_string, '_:eve', 'blank ntriples_string');
ok(Attean::Literal->integer(1)->ebv, '1 EBV');
ok(not(Attean::Literal->integer(0)->ebv), '0 EBV');
ok(not(literal('')->ebv), '"" EBV');
ok(literal('foo')->ebv, '"foo" EBV');
ok(blank('foo')->ebv, '_:foo EBV');
ok(iri('foo')->ebv, '<foo> EBV');
is(dtliteral('1', "${XSD}integer")->numeric_value, 1, 'integer numeric value');
is(dtliteral('1.5', "${XSD}float")->numeric_value, 1.5, 'float numeric value');
is(dtliteral('2.2e3', "${XSD}double")->numeric_value, 2200, 'double numeric value');
is(dtliteral('2.5', "${XSD}decimal")->numeric_value, 2.5, 'decimal numeric value');
subtest 'term type check methods' => sub {
my $xl = literal("ð¶\\\nâª");
my $dtl = dtliteral('1', "${XSD}integer");
my $ll = langliteral('Eve', 'en');
foreach my $l ($xl, $dtl, $ll) {
ok($l->is_literal);
foreach my $type (qw(variable blank resource iri)) {
my $method = "is_$type";
ok(not($l->$method()));
}
}
};
{
my $l1 = literal(7);
my $l2 = literal(10);
is($l1->compare($l2), 1, 'non-numeric literal sort');
}
{
my $i1 = Attean::Literal->integer(7);
my $i2 = Attean::Literal->integer(10);
does_ok($i1, 'Attean::API::NumericLiteral');
does_ok($i2, 'Attean::API::NumericLiteral');
is($i1->compare($i2), -1, 'numeric literal sort');
}
subtest 'XSD type promotion' => sub {
{
my $a = dtliteral('2', 'http://www.w3.org/2001/XMLSchema#long');
my $b = dtliteral('2', 'http://www.w3.org/2001/XMLSchema#short');
is($a->binary_promotion_type($b, '+'), 'http://www.w3.org/2001/XMLSchema#long');
}
{
my $a = dtliteral('2', 'http://www.w3.org/2001/XMLSchema#positiveInteger');
my $b = dtliteral('2', 'http://www.w3.org/2001/XMLSchema#unsignedByte');
is($a->binary_promotion_type($b, '+'), 'http://www.w3.org/2001/XMLSchema#nonNegativeInteger');
}
{
my $a = dtliteral('2', 'http://www.w3.org/2001/XMLSchema#positiveInteger');
my $b = dtliteral('2', 'http://www.w3.org/2001/XMLSchema#unsignedByte');
is($a->binary_promotion_type($b, '/'), 'http://www.w3.org/2001/XMLSchema#decimal');
( run in 0.643 second using v1.01-cache-2.11-cpan-39bf76dae61 )