File: serializer-ntriples-canonical.t

package info (click to toggle)
librdf-trine-perl 1.011-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,160 kB
  • ctags: 1,053
  • sloc: perl: 17,247; makefile: 35; sql: 20
file content (45 lines) | stat: -rw-r--r-- 1,019 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
use Test::More tests => 3;
BEGIN { use_ok('RDF::Trine::Serializer::NTriples::Canonical') };

use strict;
use warnings;

use RDF::Trine;
use RDF::Trine::Parser;

my $data = <<"DATA";
# Hello
_:a <eg:zee> "why" . 
_:a <eg:prop> "val" .
<eg:b> <eg:prop> _:b .
_:b3 <eg:prop> "val" .
# World
DATA

my $model	= RDF::Trine::Model->new( RDF::Trine::Store->temporary_store );
my $parser	= RDF::Trine::Parser->new('turtle');
$parser->parse_into_model(undef, $data, $model);

my $serializer	= RDF::Trine::Serializer::NTriples::Canonical->new( onfail=>'space' );
my $testString	= $serializer->serialize_model_to_string($model);

my $correctString = <<"END";
<eg:b> <eg:prop> _:g1 .\r
_:g2 <eg:prop> "val" .\r
_:g2 <eg:zee> "why" .\r
\r
_:h3 <eg:prop> "val" .\r
END

is($testString, $correctString, "canonicalisation works");

{
	my ($rh, $wh);
	pipe($rh, $wh);
	$serializer->serialize_model_to_file($wh, $model);
	close($wh);
	
	local($/)	= undef;
	my $string	= <$rh>;
	is( $string, $correctString, 'serialize_model_to_file' );
}