| 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 -no_pragmas => 1; |
| 16 |
use if $ENV{AUTHOR_TESTING}, 'Test2::Warnings'; |
| 17 |
use Test2::Tools::Exception; |
| 18 |
use Test::File::ShareDir -share => { -dist => { 'Test-JSON-Schema-Acceptance' => 'share' } }; |
| 19 |
use Test::JSON::Schema::Acceptance; |
| 20 |
|
| 21 |
is( |
| 22 |
Test::JSON::Schema::Acceptance->new->specification, |
| 23 |
'draft2020-12', |
| 24 |
'"specification" defaults to latest draft' |
| 25 |
); |
| 26 |
|
| 27 |
is( |
| 28 |
Test::JSON::Schema::Acceptance->new(specification => 'latest')->specification, |
| 29 |
'draft2020-12', |
| 30 |
'latest becomes draft2020-12', |
| 31 |
); |
| 32 |
|
| 33 |
foreach my $version (3,4,6,7) { |
| 34 |
is( |
| 35 |
Test::JSON::Schema::Acceptance->new($version)->specification, |
| 36 |
'draft'.$version, |
| 37 |
'->new('.$version.') becomes ->new(specification => \'draft'.$version.'\')', |
| 38 |
); |
| 39 |
|
| 40 |
is( |
| 41 |
Test::JSON::Schema::Acceptance->new(specification => 'draft'.$version)->specification, |
| 42 |
'draft'.$version, |
| 43 |
'->new(specification => '.$version.') passed through normally', |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
foreach my $version ('a', 2, 'foo') { |
| 48 |
like( |
| 49 |
dies { Test::JSON::Schema::Acceptance->new($version) }, |
| 50 |
qr/Value "draft$version" did not pass type constraint/, |
| 51 |
'does not accept version = '.$version, |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
like( |
| 56 |
dies { Test::JSON::Schema::Acceptance->new(test_dir => 'foo') }, |
| 57 |
qr/test_dir does not exist: .*foo/, |
| 58 |
'explicit test_dir argument is checked', |
| 59 |
); |
| 60 |
|
| 61 |
SKIP: { |
| 62 |
skip 'this test can only be run in the git repository', 1 if not -d '.git'; |
| 63 |
|
| 64 |
is(readlink('share/tests/latest'), 'draft2020-12', 'latest draft is still 2020-12') |
| 65 |
or warn 'a new draft has been released! update the "latest" munging in BUILDARGS!'; |
| 66 |
} |
| 67 |
|
| 68 |
done_testing; |