File: 05parsing-dt.t

package info (click to toggle)
libhtml-html5-microdata-parser-perl 0.100-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 400 kB
  • sloc: perl: 4,036; makefile: 7; sh: 1
file content (158 lines) | stat: -rw-r--r-- 5,499 bytes parent folder | download | duplicates (3)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
use Test::More tests => 14;
use Test::RDF;

use HTML::HTML5::Microdata::Parser;
use RDF::Trine qw[iri literal variable statement blank];
use RDF::Trine::Namespace qw[rdf rdfs xsd owl];
my $s = RDF::Trine::Namespace->new('http://schema.org/');

my $p = HTML::HTML5::Microdata::Parser->new(<<'MARKUP', 'http://example.com/', {xhtml_time=>1});
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Alice</h1>
	<time itemprop="birthday">1980-06-01</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Bob</h1>
	<time itemprop="birthday" datetime="1980-06-02">2 June 1980</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Carol</h1>
	<time itemprop="birthday" datetime="1980-06">June 1980</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">David</h1>
	<time itemprop="birthday" datetime="1980">1980</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Eve</h1>
	<time itemprop="birthday" datetime="1980-06-03T12:00pm">3 June 1980</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Fred</h1>
	<time itemprop="birthday" datetime="1980-06-04T12:00:00Z">4 June 1980</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Georgia</h1>
	<time itemprop="birthday" datetime="1980-06-05T12:00:00.000Z">5 June 1980</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Harold</h1>
	<time itemprop="birthday" datetime="1980-06-06T12:00+0100">6 June 1980</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Ingrid</h1>
	<time itemprop="birthday" datetime="--06-07">7 June</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">John</h1>
	<time itemprop="birthday" datetime="---08">The 8th</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Kylie</h1>
	<time itemprop="birthday" datetime="--06">June</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Lesley</h1>
	<time itemprop="birthday">12:00</time>
</div>
<div itemscope itemtype="http://schema.org/Person">
	<h1 itemprop="name">Maurice</h1>
	<time itemprop="birthday">12:00:01.123456789-05:00</time>
</div>
MARKUP

pattern_target($p->graph);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Alice')),
	statement(variable('x'), $s->birthday, literal('1980-06-01', undef, $xsd->date->uri)),
	'<time> with no @datetime'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Bob')),
	statement(variable('x'), $s->birthday, literal('1980-06-02', undef, $xsd->date->uri)),
	'xsd:date'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Carol')),
	statement(variable('x'), $s->birthday, literal('1980-06', undef, $xsd->gYearMonth->uri)),
	'xsd:gYearMonth'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('David')),
	statement(variable('x'), $s->birthday, literal('1980', undef, $xsd->gYear->uri)),
	'xsd:gYear'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Eve')),
	statement(variable('x'), $s->birthday, literal('1980-06-03T12:00pm', undef, undef)),
	'Malformed dateTime not given a datatype'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Fred')),
	statement(variable('x'), $s->birthday, literal('1980-06-04T12:00:00Z', undef, $xsd->dateTime->uri)),
	'xsd:dateTime'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Georgia')),
	statement(variable('x'), $s->birthday, literal('1980-06-05T12:00:00.000Z', undef, $xsd->dateTime->uri)),
	'xsd:dateTime with fractional seconds'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Harold')),
	statement(variable('x'), $s->birthday, literal('1980-06-06T12:00+0100', undef, $xsd->dateTime->uri)),
	'non-Z timezone'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Ingrid')),
	statement(variable('x'), $s->birthday, literal('--06-07', undef, $xsd->gMonthDay->uri)),
	'xsd:gMonthDay'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('John')),
	statement(variable('x'), $s->birthday, literal('---08', undef, $xsd->gDay->uri)),
	'xsd:gDay'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Kylie')),
	statement(variable('x'), $s->birthday, literal('--06', undef, $xsd->gMonth->uri)),
	'xsd:gMonth'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Lesley')),
	statement(variable('x'), $s->birthday, literal('12:00', undef, $xsd->time->uri)),
	'xsd:time'
	);

pattern_ok(
	statement(variable('x'), $rdf->type, $s->Person),
	statement(variable('x'), $s->name, literal('Maurice')),
	statement(variable('x'), $s->birthday, literal('12:00:01.123456789-05:00', undef, $xsd->time->uri)),
	'xsd:time complex'
	);

#use RDF::TrineShortcuts;
#diag rdf_string($p->graph => 'Turtle');