From 5f2d141478045feec1bca0e7ddb3792d1283a016 Mon Sep 17 00:00:00 2001 From: Gregory Todd Williams Date: Sun, 10 Apr 2016 11:39:53 -0700 Subject: [PATCH] Add end-to-end Turtle abbreviation tests (#53). --- t/serializer-turtle.t | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/t/serializer-turtle.t b/t/serializer-turtle.t index 371abf8c..532969ea 100644 --- a/t/serializer-turtle.t +++ b/t/serializer-turtle.t @@ -183,6 +183,32 @@ subtest 'token serialization' => sub { like($data, qr/"""world"""\^\^xsd:string/); }; +subtest 'AbbreviatingSerializer with explicit namespace map' => sub { + my $map = URI::NamespaceMap->new( { foaf => iri('http://xmlns.com/foaf/0.1/') } ); + my $p = Attean->get_parser('Turtle')->new(); + my $iter = $p->parse_iter_from_bytes('@prefix foaf: . a foaf:Person ; foaf:name "Alice" .'); + my $s = Attean->get_serializer('Turtle')->new( namespaces => $map ); + my $bytes = $s->serialize_iter_to_bytes($iter); + like($bytes, qr[prefix foaf: .], 'serialization has prefix declaration'); + like($bytes, qr, 'serialization has IRI'); + like($bytes, qr/foaf:Person/, 'serialization has prefix name foaf:Person'); + like($bytes, qr/foaf:name "Alice"/, 'serialization has prefix name foaf:name'); +}; + +subtest 'End-to-end AbbreviatingSerializer' => sub { + my $map = URI::NamespaceMap->new(); + my $p = Attean->get_parser('Turtle')->new( namespaces => $map ); + my $iter = $p->parse_iter_from_bytes('@prefix foaf: . @prefix ex: . a foaf:Person ; foaf:name "Alice" .'); + my $s = Attean->get_serializer('Turtle')->new( namespaces => $map ); + my $bytes = $s->serialize_iter_to_bytes($iter); + like($bytes, qr[prefix ex: .], 'serialization has prefix declaration ex:'); + like($bytes, qr[prefix foaf: .], 'serialization has prefix declaration'); + like($bytes, qr, 'serialization has IRI'); + like($bytes, qr/foaf:Person/, 'serialization has prefix name foaf:Person'); + like($bytes, qr/foaf:name "Alice"/, 'serialization has prefix name foaf:name'); + is_deeply([sort $map->list_prefixes], [qw(ex foaf)]); +}; + done_testing(); sub expect {