File: parser.t

package info (click to toggle)
librdf-trine-perl 1.019-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,200 kB
  • sloc: perl: 17,601; sql: 20; makefile: 8; sh: 1
file content (53 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (5)
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
use Test::More tests => 7;
use Test::Exception;

use strict;
use warnings;
use File::Spec;

use RDF::Trine qw(iri);
use RDF::Trine::Namespace qw(rdf foaf);
use RDF::Trine::Error qw(:try);
use RDF::Trine::Parser;

throws_ok { RDF::Trine::Parser->new('guess') } 'RDF::Trine::Error::UnimplementedError', "Guess parser isn't implemented yet";
throws_ok { RDF::Trine::Parser->new('foobar') } 'RDF::Trine::Error::ParserError', "RDF::Trine::Parser constructor throws on unrecognized parser name";


SKIP: {
	unless ($ENV{RDFTRINE_NETWORK_TESTS}) {
		skip( "No network. Set RDFTRINE_NETWORK_TESTS to run these tests.", 5 );
	}
	
	{
		my $url		= 'http://kasei.us/about/foaf.xrdf';
		my $model	= RDF::Trine::Model->new(RDF::Trine::Store->temporary_store);
		
		try {
			RDF::Trine::Parser->parse_url_into_model( $url, $model );
			pass('parse_url_into_model succeeded');
		} catch RDF::Trine::Error::ParserError with {
			fail('parse_url_into_model failed');
		};
		
		ok( $model->size, 'parsed statements' );
		my $count	= $model->count_statements( iri('http://kasei.us/about/foaf.xrdf#greg'), $rdf->type, $foaf->Person );
		is( $count, 1, 'expected statement' );
	}
	
	{
		my $url		= 'http://kasei.us/bad_file.ttl';
		my $model	= RDF::Trine::Model->new(RDF::Trine::Store->temporary_store);
		throws_ok {
			RDF::Trine::Parser->parse_url_into_model( $url, $model );
		} 'RDF::Trine::Error::ParserError', 'parse_url_into_model throws on bad URL';
	}
	
	{
		my $url		= 'tag:gwilliams@cpan.org,2012-10-18:foobar';
		my $model	= RDF::Trine::Model->new(RDF::Trine::Store->temporary_store);
		throws_ok {
			RDF::Trine::Parser->parse_url_into_model( $url, $model );
		} 'RDF::Trine::Error::ParserError', 'parse_url_into_model throws on bad URL hostname';
	}
}