File: 03lang.t

package info (click to toggle)
librdf-rdfa-parser-perl 1.097-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,948 kB
  • sloc: perl: 6,582; makefile: 7; xml: 6; sh: 1
file content (66 lines) | stat: -rw-r--r-- 2,321 bytes parent folder | download | duplicates (2)
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
# Tests that lang tags work properly

use Test::More tests => 8;
BEGIN { use_ok('RDF::RDFa::Parser') };

my $xhtml_rdfa_10 = RDF::RDFa::Parser::Config->new('xhtml','1.0');

my $xhtml = <<EOF;
<html xmlns:ex="http://example.com/ns#"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns="http://www.w3.org/1999/xhtml"
	xml:lang="en-gb">
	<body>
		<div about="[ex:r0]" property="ex:test" content="English" />
		<div lang="de" about="[ex:r1]" property="ex:test" content="English" />
		<div xml:lang="invalid-lang-tags" about="[ex:r2]" property="ex:test" content="English" />
		<div xml:lang="" about="[ex:r3]" property="ex:test" content="Empty" />
	</body>
</html>
EOF

my $parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/', $xhtml_rdfa_10);
$parser->consume;

my $model;
ok($model = $parser->graph, "Graph retrieved");

ok($model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r0'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		RDF::Trine::Node::Literal->new('English', 'en-gb'),
		),
	"Language tags are being picked up.");

ok($model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r1'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		RDF::Trine::Node::Literal->new('English', 'en-gb'),
		),
	"Non-XML lang tags are correctly ignored.");

ok($model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r2'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		RDF::Trine::Node::Literal->new('English', 'en-gb'),
		),
	"Invalid XML lang tags are correctly ignored.");

ok($model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r3'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		RDF::Trine::Node::Literal->new('Empty'),
		),
	"Empty XML lang tags reset the language.");


$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/', {xhtml_lang=>1});
$parser->consume;
ok($model = $parser->graph, "Alternative graph retrieved");

ok($model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r1'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		RDF::Trine::Node::Literal->new('English', 'de'),
		),
	"XHTML lang tags are not ignored when that option is requested.");