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
|
=head1 PURPOSE
Some basic Tests for handling of unicode characters in JSON data.
=head1 AUTHOR
Heiko Jansen E<lt>hjansen@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
Copyright 2016 Heiko Jansen.
This module is tri-licensed. It is available under the X11 (a.k.a. MIT)
licence; you can also redistribute it and/or modify it under the same
terms as Perl itself.
=cut
use Test2::V0 '-target' => 'JSON::Path';
use JSON::MaybeXS;
my $data = <<"JSON";
{
"store": {
"book": [
{
"category": "reference",
"author": "Randal L. Schwartz",
"title": "Einf\xFChrung in Perl",
"isbn": "9783868991451",
"price": 34.90
},
{
"category": "chartest",
"author": "\x{61}\x{0300}\x{0320}. u. thor",
"title": "Me \x{2661} Unicode",
"price": 0.0
}
],
"bicycle": {
"color": "r\xF6tlich",
"price": 19.95
}
}
}
JSON
utf8::encode($data);
my $object = decode_json($data);
my $path1 = JSON::Path->new('$.store.book[0].title');
is( "$path1", '$.store.book[0].title', "overloaded stringification" );
my @results1 = $path1->values($object);
is( $results1[0], "Einf\xFChrung in Perl", "basic value result" );
@results1 = $path1->paths($object);
is( $results1[0], "\$['store']['book']['0']['title']", "basic path result" );
my $path2 = JSON::Path->new('$.store.book[1].author');
my @results2 = $path2->values($object);
is( $results2[0], "\x{61}\x{0300}\x{0320}. u. thor", "basic value result" );
done_testing;
|