File: parser-rdfpatch.t

package info (click to toggle)
librdf-trine-perl 1.015-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,188 kB
  • ctags: 1,059
  • sloc: perl: 17,584; makefile: 30; sql: 20
file content (95 lines) | stat: -rw-r--r-- 2,803 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use Test::More;
use Test::Exception;
use strict;
use warnings;

use RDF::Trine qw(iri blank literal);
use RDF::Trine::Parser;
use RDF::Trine::Parser::RDFPatch;

my $parser	= RDF::Trine::Parser::RDFPatch->new();
isa_ok( $parser, 'RDF::Trine::Parser::RDFPatch' );

my $model	= RDF::Trine::Model->new();

{
	throws_ok {
		$parser->parse_line( 'X 1 .' );
	} 'RDF::Trine::Error::ParserError', 'Bad RDF Patch operation ID threw RDF::Trine::Error::ParserError';
	like( $@, qr/Unknown/, 'Good exception description' );
}

{
	throws_ok {
		$parser->parse_line( 'A 1 .' );
	} 'RDF::Trine::Error::ParserError', 'Bad RDF Patch operation arity threw RDF::Trine::Error::ParserError';
	like( $@, qr/arity/, 'Good exception description' );
}

{
	my $op	= $parser->parse_line( "A _:a a 3 ." );
	isa_ok($op, 'RDF::Trine::Parser::RDFPatch::Op' );
	is($op->op, 'A', 'Expected RDF Patch operation ID');
	my ($st)	= $op->args;
	isa_ok($st, 'RDF::Trine::Statement');
	
	is($model->size, 0, 'Expected empty test model');
	$op->execute($model);
	is($model->size, 1, 'Expected 1-statement test model');
}

{
	my $op	= $parser->parse_line( "D _:a a 3 ." );
	isa_ok($op, 'RDF::Trine::Parser::RDFPatch::Op' );
	is($op->op, 'D', 'Expected RDF Patch operation ID');
	my ($st)	= $op->args;
	isa_ok($st, 'RDF::Trine::Statement');

	$op->execute($model);
	is($model->size, 0, 'Expected empty test model');
}

{
	my $op	= $parser->parse_line( "D _:a a 3 _:g ." );
	isa_ok($op, 'RDF::Trine::Parser::RDFPatch::Op' );
	is($op->op, 'D', 'Expected RDF Patch operation ID');
	my ($st)	= $op->args;
	isa_ok($st, 'RDF::Trine::Statement::Quad');

	$op->execute($model);
	is($model->size, 0, 'Expected empty test model');
}

{
	$parser->parse_line( "A <s> <p> 1 ." )->execute($model);
	$parser->parse_line( "A <s> <p> 2 ." )->execute($model);
	$parser->parse_line( "A <q> <r> 3 ." )->execute($model);
	
	my $op	= $parser->parse_line( "Q U <p> U ." );
	isa_ok($op, 'RDF::Trine::Parser::RDFPatch::Op' );
	is($op->op, 'Q', 'Expected RDF Patch operation ID');
	
	my $iter	= $op->execute($model);
	isa_ok($iter, 'RDF::Trine::Iterator' );
	
	my $count	= 0;
	while (my $st = $iter->next) {
		$count++;
		is($st->subject->value, 's', 'expected subject');
		like($st->object->value, qr/^[12]$/, 'expected object');
	}
	is($count, 2, 'expected result count');
}

{
	my $parser	= RDF::Trine::Parser::RDFPatch->new();
	$parser->parse_line( '@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .' );
	my $op	= $parser->parse_line( "A _:a rdf:type 3 ." );
	isa_ok($op, 'RDF::Trine::Parser::RDFPatch::Op' );
	is($op->op, 'A', 'Expected RDF Patch operation ID');
	my ($st)	= $op->args;
	isa_ok($st, 'RDF::Trine::Statement');
	is( $st->predicate->value, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'expected IRI from PrefixName' );
}

done_testing();