File: get.t

package info (click to toggle)
libjson-validator-perl 3.06%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 616 kB
  • sloc: perl: 1,308; makefile: 6
file content (25 lines) | stat: -rw-r--r-- 841 bytes parent folder | download
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
use Mojo::Base -strict;
use Test::More;
use JSON::Validator;

my $jv = JSON::Validator->new->schema(
  {
    foo => [{y => 'foo'}],
    bar => [{y => 'first'}, {y => 'second'}, {z => 'zzz'}],
  }
);

is $jv->get('/bar/2/z'), 'zzz', 'get /bar/2/z';
is $jv->get([qw(nope 404)]), undef, 'get /nope/404';
is_deeply $jv->get([qw(bar 0)]), {y => 'first'}, 'get /bar/0';

# This is not officially supported. I think maybe the callback version is the way to go,
# since it allows the JSON pointer to be passed on as well.
is_deeply $jv->get(['bar', undef, 'y']), ['first', 'second', undef],
  'get /bar/undef/y';
is_deeply $jv->get([undef, undef, 'y']), [['first', 'second', undef], ['foo']],
  'get /undef/undef/y';
is_deeply $jv->get([undef, undef, 'y'])->flatten,
  ['first', 'second', undef, 'foo'], 'get /undef/undef/y flatten';

done_testing;