Test/Neo4j/Types.pm

filter: Statementstmt 100% 374 / 374 Branchbran 100% 39 / 40 (1 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 53 / 53 Podpod 100% 7 / 7 totaltotal 100% 473 / 474 (1 uncoverable) CC 21 SCAR 6.4
CC
21
Cov
100%
__ANON__
5.0
neo4j_node_ok
3.0
neo4j_relationship_ok
3.0
CRAP 1.9
« Neo4j/Types/DateTime.pm ↑ Summary Neo4j/Types/Generic/Point.pm »
1 4 ▶use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Test::Neo4j::Types;
6 # ABSTRACT: Tools for testing Neo4j type modules
7 4 $Test::Neo4j::Types::VERSION = '2.00';
8  
9 4 ▶use Test::More 0.94;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Test::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Test::Warnings qw(warnings :no_end_test);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶BEGIN { our @EXPORT = qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
15 neo4j_node_ok
16 neo4j_relationship_ok
17 neo4j_path_ok
18 neo4j_point_ok
19 neo4j_datetime_ok
20 neo4j_duration_ok
21 neo4j_bytearray_ok
22 )}
23  
24 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 # Workaround for warnings::register_categories() being unavailable
26 # in Perl v5.12 and earlier
27 package # private
28 Neo4j::Types;
29 4 require warnings::register;
30 4 warnings::register->import;
31 }
32  
33  
34 21 ▶sub _load_module_ok {
Subroutine _load_module_ok: called CC=2 SCAR=6.9
35 21 my ($name, $package) = @_;
36
37 # We want the test to fail if the module hasn't been loaded, but the
38 # error message you get normally isn't very helpful. So this sub will
39 # check if the module is loaded and return true if that's the case.
40 # Otherwise, it will try to load the module. No eval means that if
41 # loading fails, users get the original error message. If loading
42 # succeeds, we fail the test anyway because the user is supposed to
43 # load the module (checking for this can detect bugs where the
44 # user expects their code to load the module, but it actually
45 # doesn't get loaded).
46 {
47 # Look for entries in the package's symbol table
48 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 21 ▶ return 1 if keys %{"${package}::"};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{"${package}::";} 14 7 21
50 }
51 7 diag "$package is not loaded";
52 7 $package =~ s<::></>g;
53 7 require "$package.pm";
54 7 fail $name;
55 7 return 0;
56 }
57  
58  
59 12 ▶sub _element_id_test {
Subroutine _element_id_test: called CC=1 SCAR=0.0
60 12 my ($BOTH, $ID_ONLY, $new, $class, $prefix) = @_;
61
62 12 ▶ subtest "${prefix}element_id", sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
63 12 plan tests => 6;
64
65 12 my $both = $new->($class, {%$BOTH});
66 12 my $id_only = $new->($class, {%$ID_ONLY});
67 12 ▶ lives_ok { $both->element_id } 'optional op element_id' if $both->can('element_id');
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $both->can("element_id") 4 8 12
68 12 ▶ dies_ok { $both->element_id } 'optional op element_id' if ! $both->can('element_id');
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless $both->can("element_id") 8 4 12
69 SKIP: {
70 12 ▶ skip 'optional op element_id unimplemented', 2+3 unless $class->can('element_id');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can("element_id") 8 4 12
71 4 my ($element_id, $id) = map { "$prefix$_" } qw( element_id id );
72
73 # When both IDs are present, id() MAY warn
74 4 is $both->$element_id(), $BOTH->{$element_id}, "$element_id";
75 4 ▶ warnings { is $both->$id(), $BOTH->{$id}, "legacy $id" };
Subroutine __ANON__: called CC=1 SCAR=0.0
76
77 # For a missing element ID, element_id() returns the numeric ID and MUST warn
78 4 ▶ my @w_eid = warnings { is $id_only->$element_id(), $ID_ONLY->{$id}, "no $element_id with legacy $id" };
Subroutine __ANON__: called CC=1 SCAR=0.0
79 4 ok @w_eid, "no $element_id warns";
80 4 ▶ warn @w_eid if @w_eid > 1; # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
if @w_eid > 1 0 4 4
81 4 ▶ no warnings 'Neo4j::Types';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 4 ▶ ok 1 + warnings { $id_only->$element_id() } == @w_eid, "no $element_id warn cat is Neo4j::Types";
Subroutine __ANON__: called CC=1 SCAR=0.0
83 };
84 12 };
85 }
86  
87  
88 3 ▶sub _node_test {
Subroutine _node_test: called CC=1 SCAR=0.0
89 3 my ($node_class, $new) = @_;
90
91 3 plan tests => 12 + 5 + 7 + 1 + 1;
92
93 3 my ($n, @l, $p);
94
95 3 $n = $new->($node_class, my $id_only = {
96 id => 42,
97 labels => ['Foo', 'Bar'],
98 properties => { foofoo => 11, barbar => 22, '123' => [1, 2, 3] },
99 });
100 3 is $n->id(), 42, 'id';
101 3 @l = $n->labels;
102 3 is scalar(@l), 2, 'label count';
103 3 is $l[0], 'Foo', 'label Foo';
104 3 is $l[1], 'Bar', 'label Bar';
105 3 ▶ lives_and { is scalar($n->labels), 2 } 'scalar context';
Subroutine __ANON__: called CC=1 SCAR=0.0
106 3 is $n->get('foofoo'), 11, 'get foofoo';
107 3 is $n->get('barbar'), 22, 'get barbar';
108 3 is_deeply $n->get('123'), [1, 2, 3], 'get 123';
109 3 $p = $n->properties;
110 3 is ref($p), 'HASH', 'props ref';
111 3 is $p->{foofoo}, 11, 'props foofoo';
112 3 is $p->{barbar}, 22, 'props barbar';
113 3 is_deeply $p->{123}, [1, 2, 3], 'props 123';
114
115 3 $n = $new->($node_class, {
116 id => 0,
117 properties => { '0' => [] },
118 });
119 3 is $n->id(), 0, 'id 0';
120 3 is ref($n->get('0')), 'ARRAY', 'get 0 ref';
121 3 ▶ lives_and { is scalar(@{$n->get('0')}), 0 } 'get 0 empty';
Subroutine __ANON__: called CC=1 SCAR=0.0
122 3 $p = $n->properties;
123 3 is_deeply $p, {0=>[]}, 'props deeply';
124 3 is_deeply [$n->properties], [{0=>[]}], 'props list context';
125
126 3 $n = $new->($node_class, { });
127 3 ok ! defined($n->id), 'id gigo';
128 3 @l = $n->labels;
129 3 is scalar(@l), 0, 'no labels';
130 3 ▶ lives_and { is scalar($n->labels), 0 } 'scalar context no labels';
Subroutine __ANON__: called CC=1 SCAR=0.0
131 3 $p = $n->properties;
132 3 is ref($p), 'HASH', 'empty props ref';
133 3 is scalar(keys %$p), 0, 'empty props empty';
134 3 is_deeply [$n->get('whatever')], [undef], 'prop undef';
135 3 ok ! exists $n->properties->{whatever}, 'prop remains non-existent';
136
137 # element ID
138 3 my $both = { element_id => 'e17', id => 17 };
139 3 _element_id_test($both, $id_only, $new, $node_class, '');
140
141 3 isa_ok $n, 'Neo4j::Types::Node';
142 }
143  
144  
145 4 ▶sub neo4j_node_ok {
Subroutine neo4j_node_ok: called CC=3 SCAR=11.0
Pod documented
146 4 my ($class, $new, $name) = @_;
147 4 ▶ $name = "neo4j_node_ok '$class'" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 2 4
148 _load_module_ok($name, $class) and
149 4 ▶ subtest $name, sub { _node_test($class, $new) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
_load_module_ok($name, $class) and subtest($name, sub { _node_test($class, $new); } ) 3 1 4
150 }
151  
152  
153 3 ▶sub _relationship_test {
Subroutine _relationship_test: called CC=1 SCAR=0.0
154 3 my ($rel_class, $new) = @_;
155
156 3 plan tests => 11 + 5 + 8 + 3 + 1;
157
158 3 my ($r, $p);
159
160 3 $r = $new->($rel_class, my $id_only = {
161 id => 55,
162 type => 'TEST',
163 start_id => 34,
164 end_id => 89,
165 properties => { foo => 144, bar => 233, '358' => [3, 5, 8] },
166 });
167 3 is $r->id, 55, 'id';
168 3 is $r->type, 'TEST', 'type';
169 3 is $r->start_id, 34, 'start id';
170 3 is $r->end_id, 89, 'end id';
171 3 is $r->get('foo'), 144, 'get foo';
172 3 is $r->get('bar'), 233, 'get bar';
173 3 is_deeply $r->get('358'), [3, 5, 8], 'get 358';
174 3 $p = $r->properties;
175 3 is ref($p), 'HASH', 'props ref';
176 3 is $p->{foo}, 144, 'props foo';
177 3 is $p->{bar}, 233, 'props bar';
178 3 is_deeply $p->{358}, [3, 5, 8], 'props 358';
179
180 3 $r = $new->($rel_class, {
181 id => 0,
182 properties => { '0' => [] },
183 });
184 3 is $r->id(), 0, 'id 0';
185 3 is ref($r->get('0')), 'ARRAY', 'get 0 ref';
186 3 ▶ lives_and { is scalar(@{$r->get('0')}), 0 } 'get 0 empty';
Subroutine __ANON__: called CC=1 SCAR=0.0
187 3 $p = $r->properties;
188 3 is_deeply $p, {0=>[]}, 'props deeply';
189 3 is_deeply [$r->properties], [{0=>[]}], 'props list context';
190
191 3 $r = $new->($rel_class, { });
192 3 ok ! defined($r->id), 'id gigo';
193 3 ok ! defined($r->type), 'no type';
194 3 ok ! defined($r->start_id), 'no start id';
195 3 ok ! defined($r->end_id), 'no end id';
196 3 $p = $r->properties;
197 3 is ref($p), 'HASH', 'empty props ref';
198 3 is scalar(keys %$p), 0, 'empty props empty';
199 3 is_deeply [$r->get('whatever')], [undef], 'prop undef';
200 3 ok ! exists $r->properties->{whatever}, 'prop remains non-existent';
201
202 # element ID
203 3 my $both = {
204 element_id => 'e60', id => 60,
205 start_element_id => 'e61', start_id => 61,
206 end_element_id => 'e62', end_id => 62,
207 };
208 3 _element_id_test($both, $id_only, $new, $rel_class, '');
209 3 _element_id_test($both, $id_only, $new, $rel_class, 'start_');
210 3 _element_id_test($both, $id_only, $new, $rel_class, 'end_');
211
212 3 isa_ok $r, 'Neo4j::Types::Relationship';
213 }
214  
215  
216 4 ▶sub neo4j_relationship_ok {
Subroutine neo4j_relationship_ok: called CC=3 SCAR=11.0
Pod documented
217 4 my ($class, $new, $name) = @_;
218 4 ▶ $name = "neo4j_relationship_ok '$class'" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 2 4
219 _load_module_ok($name, $class) and
220 4 ▶ subtest $name, sub { _relationship_test($class, $new) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
_load_module_ok($name, $class) and subtest($name, sub { _relationship_test($class, $new); } ) 3 1 4
221 }
222  
223  
224 2 ▶sub _path_test {
Subroutine _path_test: called CC=1 SCAR=0.0
225 2 my ($path_class, $new) = @_;
226
227 2 plan tests => 3 + 3 + 6 + 6 + 1;
228
229 2 my (@p, $p, @e);
230
231 6 ▶ my $new_path = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
232 6 my $i = 0;
233 6 ▶ map { my $o = $_; bless \$o, 'Test::Neo4j::Types::Path' . ($i++ & 1 ? 'Rel' : 'Node') } @_;
Branch: 1 branch
BranchTrueFalseTotal
$i++ & 1 ? : 6 12 18
234 2 };
235
236 2 @p = $new_path->( \6, \7, \8 );
237 2 $p = $new->($path_class, { elements => \@p });
238 2 @e = $p->elements;
239 2 is_deeply [@e], [@p], 'deeply elements 3';
240 2 @e = $p->nodes;
241 2 is_deeply [@e], [$p[0],$p[2]], 'deeply nodes 2';
242 2 @e = $p->relationships;
243 2 is_deeply [@e], [$p[1]], 'deeply rel 1';
244
245 2 @p = $new_path->( \9 );
246 2 $p = $new->($path_class, { elements => \@p });
247 2 @e = $p->elements;
248 2 is_deeply [@e], [@p], 'deeply elements 1';
249 2 @e = $p->nodes;
250 2 is_deeply [@e], [$p[0]], 'deeply nodes 1';
251 2 @e = $p->relationships;
252 2 is_deeply [@e], [], 'deeply rel 0';
253
254 2 @p = $new_path->( \1, \2, \3, \4, \5 );
255 2 $p = $new->($path_class, { elements => \@p });
256 2 @e = $p->elements;
257 2 is_deeply [@e], [@p], 'deeply elements 5';
258 2 ▶ lives_and { is scalar($p->elements), 5 } 'scalar context elements';
Subroutine __ANON__: called CC=1 SCAR=0.0
259 2 @e = $p->nodes;
260 2 is_deeply [@e], [$p[0],$p[2],$p[4]], 'deeply nodes 3';
261 2 ▶ lives_and { is scalar($p->nodes), 3 } 'scalar context nodes';
Subroutine __ANON__: called CC=1 SCAR=0.0
262 2 @e = $p->relationships;
263 2 is_deeply [@e], [$p[1],$p[3]], 'deeply rel 2';
264 2 ▶ lives_and { is scalar($p->relationships), 2 } 'scalar context relationships';
Subroutine __ANON__: called CC=1 SCAR=0.0
265
266 2 $p = $new->($path_class, { elements => [] });
267 2 @e = $p->elements;
268 2 is scalar(@e), 0, 'no elements gigo';
269 2 ▶ lives_and { is scalar($p->elements), 0 } 'scalar context no elements';
Subroutine __ANON__: called CC=1 SCAR=0.0
270 2 @e = $p->nodes;
271 2 is scalar(@e), 0, 'no nodes 0 gigo';
272 2 ▶ lives_and { is scalar($p->nodes), 0 } 'scalar context no nodes';
Subroutine __ANON__: called CC=1 SCAR=0.0
273 2 @e = $p->relationships;
274 2 is scalar(@e), 0, 'no relationships 0 gigo';
275 2 ▶ lives_and { is scalar($p->relationships), 0 } 'scalar context no relationships';
Subroutine __ANON__: called CC=1 SCAR=0.0
276
277 2 isa_ok $p, 'Neo4j::Types::Path';
278 }
279  
280  
281 3 ▶sub neo4j_path_ok {
Subroutine neo4j_path_ok: called CC=3 SCAR=11.0
Pod documented
282 3 my ($class, $new, $name) = @_;
283 3 ▶ $name = "neo4j_path_ok '$class'" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 1 3
284 _load_module_ok($name, $class) and
285 3 ▶ subtest $name, sub { _path_test($class, $new) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
_load_module_ok($name, $class) and subtest($name, sub { _path_test($class, $new); } ) 2 1 3
286 }
287  
288  
289 2 ▶sub _point_test {
Subroutine _point_test: called CC=1 SCAR=0.0
290 2 my ($point_class, $new) = @_;
291
292 2 plan tests => 3+3 + 3+3+3+3+2 + 1;
293
294 2 my (@c, $p);
295
296
297 # Simple point, location in real world
298 2 @c = ( 2.294, 48.858, 396 );
299 2 $p = $new->( $point_class, { srid => 4979, coordinates => [@c] });
300 2 is $p->srid(), 4979, 'eiffel srid';
301 2 is_deeply [$p->coordinates], [@c], 'eiffel coords';
302 2 is scalar ($p->coordinates), 3, 'scalar context eiffel coords';
303
304 2 @c = ( 2.294, 48.858 );
305 2 $p = $new->( $point_class, { srid => 4326, coordinates => [@c] });
306 2 is $p->srid(), 4326, 'eiffel 2d srid';
307 2 is_deeply [$p->coordinates], [@c], 'eiffel 2d coords';
308 2 is scalar ($p->coordinates), 2, 'scalar context eiffel 2d coords';
309
310
311 # Other SRSs, location not in real world
312 2 @c = ( 12, 34 );
313 2 $p = $new->( $point_class, { srid => 7203, coordinates => [@c] });
314 2 is $p->srid(), 7203, 'plane srid';
315 2 is_deeply [$p->coordinates], [@c], 'plane coords';
316 2 is scalar ($p->coordinates), 2, 'scalar context plane coords';
317
318 2 @c = ( 56, 78, 90 );
319 2 $p = $new->( $point_class, { srid => 9157, coordinates => [@c] });
320 2 is $p->srid(), 9157, 'space srid';
321 2 is_deeply [$p->coordinates], [@c], 'space coords';
322 2 is scalar ($p->coordinates), 3, 'scalar context space coords';
323
324 2 @c = ( 361, -91 );
325 2 $p = $new->( $point_class, { srid => 4326, coordinates => [@c] });
326 2 is $p->srid(), 4326, 'ootw srid';
327 2 is_deeply [$p->coordinates], [@c], 'ootw coords';
328 2 is scalar ($p->coordinates), 2, 'scalar context ootw coords';
329
330 2 @c = ( 'what', 'ever' );
331 2 $p = $new->( $point_class, { srid => '4326', coordinates => [@c] });
332 2 is $p->srid(), '4326', 'string srid';
333 2 is_deeply [$p->coordinates], [@c], 'string coords';
334 2 is scalar ($p->coordinates), 2, 'scalar context string coords';
335
336 2 @c = ( undef, 45 );
337 2 $p = $new->( $point_class, { srid => 7203, coordinates => [@c] });
338 2 is_deeply [$p->coordinates], [@c], 'undef coord';
339 2 is scalar ($p->coordinates), 2, 'scalar context undef coord';
340
341
342 2 isa_ok $p, 'Neo4j::Types::Point';
343 }
344  
345  
346 3 ▶sub neo4j_point_ok {
Subroutine neo4j_point_ok: called CC=3 SCAR=11.0
Pod documented
347 3 my ($class, $new, $name) = @_;
348 3 ▶ $name = "neo4j_point_ok '$class'" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 1 3
349 _load_module_ok($name, $class) and
350 3 ▶ subtest $name, sub { _point_test($class, $new) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
_load_module_ok($name, $class) and subtest($name, sub { _point_test($class, $new); } ) 2 1 3
351 }
352  
353  
354 2 ▶sub _datetime_test {
Subroutine _datetime_test: called CC=1 SCAR=0.0
355 2 my ($datetime_class, $new) = @_;
356
357 2 plan tests => 9 * 7 + 1;
358
359 2 my ($dt, $p, $type);
360
361 2 $type = 'DATE';
362 2 $dt = $new->($datetime_class, $p = {
363 days => 18645, # 2021-01-18
364 });
365 2 is $dt->days, $p->{days}, 'date: days';
366 2 is $dt->epoch, 1610928000, 'date: epoch';
367 2 is $dt->nanoseconds, $p->{nanoseconds}, 'date: no nanoseconds';
368 2 is $dt->seconds, $p->{seconds}, 'date: no seconds';
369 2 is $dt->type, $type, 'date: type';
370 2 is $dt->tz_name, $p->{tz_name}, 'date: no tz_name';
371 2 is $dt->tz_offset, $p->{tz_offset}, 'date: no tz_offset';
372
373 2 $type = 'LOCAL TIME';
374 2 $dt = $new->($datetime_class, $p = {
375 nanoseconds => 1,
376 });
377 2 is $dt->days, $p->{days}, 'local time: no days';
378 2 is $dt->epoch, 0, 'local time: epoch';
379 2 is $dt->nanoseconds, $p->{nanoseconds}, 'local time: nanoseconds';
380 2 is $dt->seconds, 0, 'local time: seconds';
381 2 is $dt->type, $type, 'local time: type';
382 2 is $dt->tz_name, $p->{tz_name}, 'local time: no tz_name';
383 2 is $dt->tz_offset, $p->{tz_offset}, 'local time: no tz_offset';
384
385 2 $type = 'ZONED TIME';
386 2 $dt = $new->($datetime_class, $p = {
387 seconds => 86340, # 23:59
388 nanoseconds => 5e8, # 0.5 s
389 tz_offset => -28800, # -8 h
390 });
391 2 is $dt->days, $p->{days}, 'zoned time: no days';
392 2 is $dt->epoch, 86340, 'zoned time: epoch';
393 2 is $dt->nanoseconds, $p->{nanoseconds}, 'zoned time: nanoseconds';
394 2 is $dt->seconds, $p->{seconds}, 'zoned time: seconds';
395 2 is $dt->type, $type, 'zoned time: type';
396 2 is $dt->tz_name, 'Etc/GMT+8', 'zoned time: tz_name';
397 2 is $dt->tz_offset, $p->{tz_offset}, 'zoned time: tz_offset';
398
399 2 $type = 'LOCAL DATETIME';
400 2 $dt = $new->($datetime_class, $p = {
401 days => -1,
402 seconds => 86399,
403 });
404 2 is $dt->days, $p->{days}, 'local datetime: days';
405 2 is $dt->epoch, -1, 'local datetime: epoch';
406 2 is $dt->nanoseconds, 0, 'local datetime: nanoseconds';
407 2 is $dt->seconds, $p->{seconds}, 'local datetime: seconds';
408 2 is $dt->type, $type, 'local datetime: type';
409 2 is $dt->tz_name, $p->{tz_name}, 'local datetime: no tz_name';
410 2 is $dt->tz_offset, $p->{tz_offset}, 'local datetime: no tz_offset';
411
412 2 $type = 'ZONED DATETIME';
413 2 $dt = $new->($datetime_class, $p = {
414 days => 7252, # 1989-11-09
415 seconds => 61043, # 17:57:23 UTC
416 nanoseconds => 0,
417 tz_offset => 5400, # +1.5 h
418 });
419 2 is $dt->days, $p->{days}, 'zoned datetime (offset): days';
420 2 is $dt->epoch, 626633843, 'zoned datetime (offset): epoch';
421 2 is $dt->nanoseconds, $p->{nanoseconds}, 'zoned datetime (offset): nanoseconds';
422 2 is $dt->seconds, $p->{seconds}, 'zoned datetime (offset): seconds';
423 2 is $dt->type, $type, 'zoned datetime (offset): type';
424 2 is $dt->tz_name, undef, 'zoned datetime (half hour offset): no tz_name';
425 2 is $dt->tz_offset, $p->{tz_offset}, 'zoned datetime (offset): tz_offset';
426
427 2 $dt = $new->($datetime_class, $p = {
428 days => 6560, # 1987-12-18
429 seconds => 72000, # 20:00 UTC
430 nanoseconds => 0,
431 tz_name => 'America/Los_Angeles',
432 });
433 2 is $dt->days, $p->{days}, 'zoned datetime: days';
434 2 is $dt->epoch, 566856000, 'zoned datetime: epoch';
435 2 is $dt->nanoseconds, $p->{nanoseconds}, 'zoned datetime: nanoseconds';
436 2 is $dt->seconds, $p->{seconds}, 'zoned datetime: seconds';
437 2 is $dt->type, $type, 'zoned datetime: type';
438 2 is $dt->tz_name, $p->{tz_name}, 'zoned datetime: tz_name';
439 2 is $dt->tz_offset, $p->{tz_offset}, 'zoned datetime: no tz_offset';
440
441 2 $dt = $new->($datetime_class, $p = {
442 days => 0,
443 seconds => 0,
444 tz_offset => 0, # GMT
445 });
446 2 is $dt->days, 0, 'zoned datetime (zero offset): days';
447 2 is $dt->epoch, 0, 'zoned datetime (zero offset): epoch';
448 2 is $dt->nanoseconds, 0, 'zoned datetime (zero offset): nanoseconds';
449 2 is $dt->seconds, 0, 'zoned datetime (zero offset): seconds';
450 2 is $dt->type, $type, 'zoned datetime (zero offset): type';
451 2 like $dt->tz_name, qr<^Etc/GMT(?:[-+]0)?$>, 'zoned datetime (zero offset): tz_name';
452 2 is $dt->tz_offset, 0, 'zoned datetime (zero offset): tz_offset';
453
454 2 $dt = $new->($datetime_class, $p = {
455 days => 0,
456 seconds => 0,
457 tz_offset => 86400, # Zone Etc/GMT-24 doesn't exist
458 });
459 2 is $dt->days, 0, 'zoned datetime (too high offset): days';
460 2 is $dt->epoch, 0, 'zoned datetime (too high offset): epoch';
461 2 is $dt->nanoseconds, 0, 'zoned datetime (too high offset): nanoseconds';
462 2 is $dt->seconds, 0, 'zoned datetime (too high offset): seconds';
463 2 is $dt->type, $type, 'zoned datetime (too high offset): type';
464 2 is $dt->tz_name, undef, 'zoned datetime (too high offset): no tz_name';
465 2 is $dt->tz_offset, 86400, 'zoned datetime (too high offset): tz_offset';
466
467 2 $dt = $new->($datetime_class, $p = {
468 days => 0,
469 nanoseconds => 0,
470 tz_offset => -72000, # Zone Etc/GMT+20 doesn't exist
471 });
472 2 is $dt->days, 0, 'zoned datetime (too low offset): days';
473 2 is $dt->epoch, 0, 'zoned datetime (too low offset): epoch';
474 2 is $dt->nanoseconds, 0, 'zoned datetime (too low offset): nanoseconds';
475 2 is $dt->seconds, 0, 'zoned datetime (too low offset): seconds';
476 2 is $dt->type, $type, 'zoned datetime (too low offset): type';
477 2 is $dt->tz_name, undef, 'zoned datetime (too low offset): no tz_name';
478 2 is $dt->tz_offset, -72000, 'zoned datetime (too low offset): tz_offset';
479
480 2 isa_ok $dt, 'Neo4j::Types::DateTime';
481 }
482  
483  
484 3 ▶sub neo4j_datetime_ok {
Subroutine neo4j_datetime_ok: called CC=3 SCAR=11.0
Pod documented
485 3 my ($class, $new, $name) = @_;
486 3 ▶ $name = "neo4j_datetime_ok '$class'" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 2 3
487 _load_module_ok($name, $class) and
488 3 ▶ subtest $name, sub { _datetime_test($class, $new) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
_load_module_ok($name, $class) and subtest($name, sub { _datetime_test($class, $new); } ) 2 1 3
489 }
490  
491  
492 1 ▶sub _duration_test {
Subroutine _duration_test: called CC=1 SCAR=0.0
493 1 my ($duration_class, $new) = @_;
494
495 1 plan tests => 2 * 4 + 1;
496
497 1 my $d;
498
499 # Whether ISO 8601 allows negative quantities isn't entirely clear.
500 # But it does seem to make sense to allow them.
501 # However, the Neo4j server may have bugs related to this;
502 # e. g. in Neo4j 5.6, duration({months: 1, days: -1}) yields P29D,
503 # which is definitely wrong: A month must not be assumed to have a
504 # length of any particular number of days, therefore subtracting
505 # one day from a duration never changes the months count.
506
507 1 $d = $new->($duration_class, {
508 months => 18,
509 seconds => -172800,
510 });
511 1 is $d->months, 18, 'months';
512 1 is $d->days, 0, 'no days yields zero';
513 1 is $d->seconds, -172800, 'seconds';
514 1 is $d->nanoseconds, 0, 'no nanoseconds yields zero';
515
516 1 $d = $new->($duration_class, {
517 days => -42,
518 nanoseconds => 2000,
519 });
520 1 is $d->months, 0, 'no months yields zero';
521 1 is $d->days, -42, 'days';
522 1 is $d->seconds, 0, 'no seconds yields zero';
523 1 is $d->nanoseconds, 2000, 'nanoseconds';
524
525 1 isa_ok $d, 'Neo4j::Types::Duration';
526 }
527  
528  
529 2 ▶sub neo4j_duration_ok {
Subroutine neo4j_duration_ok: called CC=3 SCAR=11.0
Pod documented
530 2 my ($class, $new, $name) = @_;
531 2 ▶ $name = "neo4j_duration_ok '$class'" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 1 2
532 _load_module_ok($name, $class) and
533 2 ▶ subtest $name, sub { _duration_test($class, $new) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
_load_module_ok($name, $class) and subtest($name, sub { _duration_test($class, $new); } ) 1 1 2
534 }
535  
536  
537 1 ▶sub _bytearray_test {
Subroutine _bytearray_test: called CC=1 SCAR=0.0
538 1 my ($bytearray_class, $new) = @_;
539
540 1 plan tests => 1 + 2 + 1;
541
542 1 my $b;
543
544 1 $b = $new->($bytearray_class, {
545 as_string => 'foo',
546 });
547 1 is $b->as_string, 'foo', 'bytes "foo"';
548
549 1 $b = $new->($bytearray_class, {
550 as_string => "\x{100}",
551 });
552 1 ok ! utf8::is_utf8($b->as_string), 'wide char bytearray: UTF8 off';
553 1 ok length($b->as_string) > 1, 'wide char bytearray: multiple bytes';
554
555 1 isa_ok $b, 'Neo4j::Types::ByteArray';
556 }
557  
558  
559 2 ▶sub neo4j_bytearray_ok {
Subroutine neo4j_bytearray_ok: called CC=3 SCAR=11.0
Pod documented
560 2 my ($class, $new, $name) = @_;
561 2 ▶ $name = "neo4j_bytearray_ok '$class'" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 1 2
562 _load_module_ok($name, $class) and
563 2 ▶ subtest $name, sub { _bytearray_test($class, $new) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
_load_module_ok($name, $class) and subtest($name, sub { _bytearray_test($class, $new); } ) 1 1 2
564 }
565  
566  
567 package Test::Neo4j::Types::PathNode;
568 4 $Test::Neo4j::Types::PathNode::VERSION = '2.00';
569 4 ▶use parent 'Neo4j::Types::Node';
Subroutine BEGIN: called CC=1 SCAR=0.0
570  
571  
572 package Test::Neo4j::Types::PathRel;
573 4 $Test::Neo4j::Types::PathRel::VERSION = '2.00';
574 4 ▶use parent 'Neo4j::Types::Relationship';
Subroutine BEGIN: called CC=1 SCAR=0.0
575  
576  
577 4 1;
« Neo4j/Types/DateTime.pm ↑ Summary Neo4j/Types/Generic/Point.pm »