Debian Codegraph @

t/03-validate_data.t

raw
1 # vim: set ts=8 sts=2 sw=2 tw=100 et :
2 use strict;
3 use warnings;
4 use 5.020;
5 use strictures 2;
6 use stable 0.031 'postderef';
7 use experimental 'signatures';
8 no autovivification warn => qw(fetch store exists delete);
9 use if "$]" >= 5.022, experimental => 're_strict';
10 no if "$]" >= 5.031009, feature => 'indirect';
11 no if "$]" >= 5.033001, feature => 'multidimensional';
12 no if "$]" >= 5.033006, feature => 'bareword_filehandles';
13 no if "$]" >= 5.041009, feature => 'smartmatch';
14
15 use Test2::API 'intercept';
16 use Test2::V0 qw(!bag !bool), -no_pragmas => 1;
17 use if $ENV{AUTHOR_TESTING}, 'Test2::Warnings';
18 use Test::Deep qw(!array !hash);;
19
20 use Test::File::ShareDir -share => { -dist => { 'Test-JSON-Schema-Acceptance' => 'share' } };
21 use Test::JSON::Schema::Acceptance;
22 use lib 't/lib';
23 use SchemaParser;
24
25 # this is similar to t/01-basic.t only it uses the new option to pass a "validate as inflated
26 # data" subref.
27
28 my $accepter = Test::JSON::Schema::Acceptance->new(specification => 'draft7');
29
30 my $parser = SchemaParser->new;
31 my $events = intercept(
32 sub {
33 $accepter->acceptance(validate_data => sub ($schema, $data) {
34 return $parser->validate_data($data, $schema);
35 });
36 }
37 );
38
39 my @bool_tests = grep $_->isa('Test2::Event::Ok') && $_->name =~ /boolean type matches booleans/,
40 @$events;
41 is(@bool_tests, 10, 'found all the tests that check for boolean type');
42
43 cmp_deeply(
44 \@bool_tests,
45 array_each(methods(
46 pass => 1,
47 effective_pass => 1,
48 )),
49 'tests pass for checking schemas that test for boolean type',
50 );
51
52 done_testing;