#!perl
my
$driver
;
BEGIN {
unless
(
$driver
= Neo4j::Test->driver) {
print
qq{1..0 # SKIP no connection to Neo4j server\n}
;
exit
;
}
}
my
$transaction
=
$driver
->session->begin_transaction;
$transaction
->{return_stats} = 0;
my
(
$r
);
sub
to_hex ($) {
return
unless
defined
$_
[0];
join
' '
,
map
{
sprintf
"%02x"
,
ord
$_
}
split
m//,
shift
;
}
my
%props
= (
singlebyte
=>
"\N{U+0025}"
,
supplement
=>
"\N{U+00E4}"
,
extension
=>
"\N{U+0100}"
,
threebytes
=>
"\N{U+D55C}"
,
smp
=>
"\N{U+1F600}"
,
decomposed
=>
"o\N{U+0302}"
,
mixed
=>
"%รคฤํ๐oฬ"
,
);
my
@keys
=
sort
keys
%props
;
my
(
@id
,
$smp_r
,
$mixed_r
,
$node
);
lives_ok {
$smp_r
=
$driver
->session->run(
'RETURN {smp}'
,
smp
=>
$props
{smp})->list->[0]->get(0);
}
'get smp'
;
is to_hex
$smp_r
, to_hex
$props
{smp},
'smp'
;
lives_ok {
$r
=
$transaction
->run(
'CREATE (n) RETURN id(n) AS id'
);
}
'create node'
;
lives_ok {
@id
= (
id
=>
$r
->list->[0]->get(
'id'
) );
}
'get node id'
;
lives_ok {
$transaction
->run(
"MATCH (n) WHERE id(n) = {id} SET n = {props}"
,
@id
,
props
=> \
%props
);
}
'write props'
;
subtest
'read single property'
=>
sub
{
plan
tests
=> 3;
lives_ok {
$r
=
$transaction
->run(
'MATCH (n) WHERE id(n) = {id} RETURN n.mixed'
,
@id
);
}
'read mixed'
;
lives_ok {
$mixed_r
=
$r
->list->[0]->get(0);
}
'get mixed_r'
;
is to_hex
$mixed_r
, to_hex
$props
{mixed},
"mixed_r"
;
};
subtest
'read full property list'
=>
sub
{
plan
tests
=> 3 +
@keys
;
lives_ok {
$r
=
undef
;
$r
=
$transaction
->run(
'MATCH (n) WHERE id(n) = {id} RETURN n'
,
@id
);
}
'read props'
;
lives_ok {
$node
=
$r
->list->[0]->get(0);
}
'get node'
;
is
ref
$node
,
'Neo4j::Driver::Type::Node'
,
'$node is blessed node'
;
foreach
my
$key
(
@keys
) {
is to_hex
$node
->get(
$key
), to_hex
$props
{
$key
},
"prop: $key"
;
}
};
CLEANUP: {
lives_ok {
$transaction
->rollback }
'rollback'
;
}
done_testing;