File: 02_kk_namespaces.t

package info (click to toggle)
librdf-rdfa-generator-perl 0.200-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 252 kB
  • sloc: perl: 885; sh: 4; makefile: 2
file content (119 lines) | stat: -rw-r--r-- 5,503 bytes parent folder | download
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env perl

# tests from KjetilK

use strict;
use Test::More;

use Attean;
use Attean::RDF qw(iri);



my $parser     = Attean->get_parser( 'turtle' )->new(base=>'http://example.org/');
my $iter = $parser->parse_iter_from_bytes( '</foo> a </Bar> .' );

my $store = Attean->get_store('Memory')->new();
$store->add_iter($iter->as_quads(iri('http://graph.invalid/')));
my $model = Attean::QuadModel->new( store => $store );

use RDF::RDFa::Generator;


subtest 'Default generator, old bugfix' => sub {
  ok(my $document = RDF::RDFa::Generator->new->create_document($model), 'Assignment OK');
  isa_ok($document, 'XML::LibXML::Document');
  my $string = $document->toString;
  
  unlike($string, qr|xmlns:http://www.w3.org/1999/02/22-rdf-syntax-ns#="rdf"|, 'RDF namespace shouldnt be reversed');
  like($string, qr|xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"|, 'Correct RDF namespace declaration');
};

subtest 'Default generator, single given NS' => sub {
  my $string = tests({ 'ex' => 'http://example.org/ns'}, 'xmlns:ex="http://example.org/ns"');
};

subtest 'Head generator, single given NS' => sub {
  my $string = tests({ 'ex' => 'http://example.org/ns'}, 'xmlns:ex="http://example.org/ns"', 'HTML::Head');

};

subtest 'Head generator, list of known prefixes' => sub {
  my $string = tests(['bibo', 'dbo', 'doap'], 'xmlns:bibo="http://purl.org/ontology/bibo/"', 'HTML::Head');
  like($string, qr|xmlns:dbo="http://dbpedia.org/ontology/"|, 'Correct dbo namespace declaration');
  like($string, qr|xmlns:doap="http://usefulinc.com/ns/doap#"|, 'Correct doap namespace declaration');
};

subtest 'Head generator, list of known uris' => sub {
  my $string = tests(["http://dbpedia.org/ontology/", "http://usefulinc.com/ns/doap#", "http://purl.org/ontology/bibo/"], 'xmlns:bibo="http://purl.org/ontology/bibo/"', 'HTML::Head');
  like($string, qr|xmlns:dbo="http://dbpedia.org/ontology/"|, 'Correct dbo namespace declaration');
  like($string, qr|xmlns:doap="http://usefulinc.com/ns/doap#"|, 'Correct doap namespace declaration');
};

subtest 'Head generator, list of unknown uris' => sub {
  my $string = tests(["http://example.org/ontology/", "http://nothinguseful.com/ns/doad#"], 'xmlns:doad="http://nothinguseful.com/ns/doad#"', 'HTML::Head');
  like($string, qr|xmlns:ontology="http://example.org/ontology/"|, 'Correct dbo namespace declaration');
};

subtest 'Pretty generator, single given NS' => sub {
  my $string = tests({ 'ex' => 'http://example.org/ns'}, 'xmlns:ex="http://example.org/ns"', 'HTML::Pretty');

};

subtest 'Pretty generator, list of known prefixes' => sub {
  my $string = tests(['bibo', 'dbo', 'doap'], 'xmlns:bibo="http://purl.org/ontology/bibo/"', 'HTML::Pretty');
  like($string, qr|xmlns:dbo="http://dbpedia.org/ontology/"|, 'Correct dbo namespace declaration');
  like($string, qr|xmlns:doap="http://usefulinc.com/ns/doap#"|, 'Correct doap namespace declaration');
};

subtest 'Pretty generator, list of known uris' => sub {
  my $string = tests(["http://dbpedia.org/ontology/", "http://usefulinc.com/ns/doap#", "http://purl.org/ontology/bibo/"], 'xmlns:bibo="http://purl.org/ontology/bibo/"', 'HTML::Pretty');
  like($string, qr|xmlns:dbo="http://dbpedia.org/ontology/"|, 'Correct dbo namespace declaration');
  like($string, qr|xmlns:doap="http://usefulinc.com/ns/doap#"|, 'Correct doap namespace declaration');
};

subtest 'Pretty generator, list of unknown uris' => sub {
  my $string = tests(["http://example.org/ontology/", "http://nothinguseful.com/ns/doad#"], 'xmlns:doad="http://nothinguseful.com/ns/doad#"', 'HTML::Pretty');
  like($string, qr|xmlns:ontology="http://example.org/ontology/"|, 'Correct dbo namespace declaration');
};

subtest 'Hidden generator, single given NS' => sub {
  my $string = tests({ 'ex' => 'http://example.org/ns'}, 'xmlns:ex="http://example.org/ns"', 'HTML::Hidden');

};

subtest 'Hidden generator, list of known prefixes' => sub {
  my $string = tests(['bibo', 'dbo', 'doap'], 'xmlns:bibo="http://purl.org/ontology/bibo/"', 'HTML::Hidden');
  like($string, qr|xmlns:dbo="http://dbpedia.org/ontology/"|, 'Correct dbo namespace declaration');
  like($string, qr|xmlns:doap="http://usefulinc.com/ns/doap#"|, 'Correct doap namespace declaration');
};

subtest 'Hidden generator, list of known uris' => sub {
  my $string = tests(["http://dbpedia.org/ontology/", "http://usefulinc.com/ns/doap#", "http://purl.org/ontology/bibo/"], 'xmlns:bibo="http://purl.org/ontology/bibo/"', 'HTML::Hidden');
  like($string, qr|xmlns:dbo="http://dbpedia.org/ontology/"|, 'Correct dbo namespace declaration');
  like($string, qr|xmlns:doap="http://usefulinc.com/ns/doap#"|, 'Correct doap namespace declaration');
};

subtest 'Hidden generator, list of unknown uris' => sub {
  my $string = tests(["http://example.org/ontology/", "http://nothinguseful.com/ns/doad#"], 'xmlns:doad="http://nothinguseful.com/ns/doad#"', 'HTML::Hidden');
  like($string, qr|xmlns:ontology="http://example.org/ontology/"|, 'Correct dbo namespace declaration');
};



sub tests {
  my ($ns, $expect, $generator) = @_;
  my %opts = (namespaces => $ns);
  if ($generator) {
	 $opts{style} = $generator;
  } else {
	 $generator = 'default';
  }
  ok(my $document = RDF::RDFa::Generator->new(%opts)->create_document($model), "Assignment of $generator generator OK");
  isa_ok($document, 'XML::LibXML::Document');
  my $string = $document->toString;
  like($string, qr|$expect|, 'Correct example namespace declaration');
  return $string;
}

done_testing();