1. Toby Inkster
  2. p5-rdf-trinex-functions

Commits

Toby Inkster  committed 5464ff4

improve parsing tests - parse from filehandles, etc

  • Participants
  • Parent commits 61bacbe
  • Branches default
  • Tags 0.003

Comments (0)

Files changed (2)

File t/02parse_and_serialise.nt

View file
  • Ignore whitespace
+<http://example.com/s> <http://example.com/p> <http://example.com/o> .

File t/02parse_and_serialise.t

View file
  • Ignore whitespace
-use Test::More tests => 2;
+use Test::More tests => 5;
 
 use RDF::Trine;
 use RDF::TrineX::Functions
 	parse     => {},
 	serialize => { -type => RDF::Trine::Serializer::NTriples::Canonical->new };
 
-my $in    = "<http://example.com/s> <http://example.com/p> <http://example.com/o> .\r\n";
-my $model = parse($in, as => 'NTriples', base => 'http://example.net/');
+my %in;
+($in{filename} = __FILE__) =~ s/t$/nt/;
+open $in{filehandle}, '<', $in{filename} or die "Could not open $in{filename}: $!";
+$in{data} = do { local (@ARGV, $/) = $in{filename}; <> };
+open $in{datahandle}, '<', \($in{data});
 
-is($model->count_statements, 1, "rdf_parse OK");
+foreach my $source (qw(data datahandle filename filehandle))
+{
+	my $model = parse(
+		$in{$source},
+		as   => 'NTriples',
+		base => 'http://example.net/',
+	);
 
-my $type;
-
-is(serialize($model), $in, "rdf_string OK");
+	is($model->count_statements, 1, "parse(<$source>) OK");
+	
+	if ($source eq 'filehandle')
+	{
+		my $out      = serialize($model);
+		my $expected = $in{data};
+		for ($out, $expected) { s/[\r\n]//g };
+		is($out, $expected, "serialize OK");
+	}
+}