| 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::V0 qw(!bag !bool), -no_pragmas => 1; |
| 16 |
use if $ENV{AUTHOR_TESTING}, 'Test2::Warnings'; |
| 17 |
use Test::JSON::Schema::Acceptance; |
| 18 |
use Test::File::ShareDir -share => { -dist => { 'Test-JSON-Schema-Acceptance' => 'share' } }; |
| 19 |
use JSON::PP; |
| 20 |
|
| 21 |
use lib 't/lib'; |
| 22 |
use Helper; |
| 23 |
|
| 24 |
my %additional_resources; |
| 25 |
|
| 26 |
my $accepter = Test::JSON::Schema::Acceptance->new( |
| 27 |
test_dir => 't/tests/add_resource', |
| 28 |
additional_resources => 't/tests/add_resource/remotes', |
| 29 |
include_optional => 0, |
| 30 |
supported_specifications => [ qw(draft2019-09 draft2020-12) ], |
| 31 |
); |
| 32 |
|
| 33 |
$accepter->acceptance( |
| 34 |
validate_data => sub ($schema, $data) { |
| 35 |
return 1; # all schemas evaluate to true here |
| 36 |
}, |
| 37 |
add_resource => sub ($uri, $schema, %options) { |
| 38 |
$additional_resources{$uri} = [ $schema, \%options ]; |
| 39 |
}, |
| 40 |
); |
| 41 |
|
| 42 |
cmp_result( |
| 43 |
\%additional_resources, |
| 44 |
{ |
| 45 |
'http://localhost:1234/remote1.json' => [ { '$defs' => { foo => bool(1) } }, {} ], |
| 46 |
'http://localhost:1234/subfolder/remote2.json' => [ { '$defs' => { bar => bool(0) } }, {} ], |
| 47 |
'http://localhost:1234/draft2020-12/remote3.json' => [ { '$defs' => { baz => bool(0) } }, { specification_version => 'draft2020-12' } ], |
| 48 |
'http://localhost:1234/draft2019-09/remote4.json' => [ { '$defs' => { quux => bool(0) } }, { specification_version => 'draft2019-09' } ], |
| 49 |
# but not http://localhost:1234/draft6/remote5.json |
| 50 |
}, |
| 51 |
'user-supplied subref is called with additional resources found in test directory', |
| 52 |
); |
| 53 |
|
| 54 |
done_testing; |