Skip to content

Commit dfe7d23

Browse files
more, potentially redundant, tests of canonical uri determination in document parsing
1 parent b2043d1 commit dfe7d23

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

t/document.t

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,4 +981,96 @@ subtest 'custom metaschema_uri' => sub {
981981
memory_cycle_ok($js, 'no leaks in the evaluator object');
982982
};
983983

984+
subtest 'multiple uris used for resolution and identification' => sub {
985+
my $js = JSON::Schema::Modern->new;
986+
my $doc = $js->add_document(
987+
'https://example.com/api/' => JSON::Schema::Modern::Document->new(
988+
canonical_uri => 'staging/',
989+
schema => {
990+
'$id' => 'alpha.json',
991+
properties => {
992+
foo => { '$id' => 'beta' },
993+
},
994+
},
995+
evaluator => $js,
996+
)
997+
);
998+
999+
cmp_deeply(
1000+
$doc,
1001+
listmethods(
1002+
canonical_uri => [ str('staging/alpha.json') ],
1003+
resource_index => unordered_pairs(
1004+
'staging/alpha.json' => {
1005+
path => '',
1006+
canonical_uri => str('staging/alpha.json'),
1007+
%configs,
1008+
},
1009+
'staging/beta' => {
1010+
canonical_uri => str('staging/beta'),
1011+
path => '/properties/foo',
1012+
%configs,
1013+
},
1014+
),
1015+
),
1016+
'document has correct resources, resolved against the provided base uri',
1017+
);
1018+
1019+
cmp_deeply(
1020+
$js->{_resource_index},
1021+
my $resource_index = {
1022+
'https://example.com/api/' => {
1023+
path => '',
1024+
canonical_uri => str('https://example.com/api/staging/alpha.json'),
1025+
document => $doc,
1026+
%configs,
1027+
},
1028+
'https://example.com/api/staging/alpha.json' => {
1029+
path => '',
1030+
canonical_uri => str('https://example.com/api/staging/alpha.json'),
1031+
document => $doc,
1032+
%configs,
1033+
},
1034+
'https://example.com/api/staging/beta' => {
1035+
path => '/properties/foo',
1036+
canonical_uri => str('https://example.com/api/staging/beta'),
1037+
document => $doc,
1038+
%configs,
1039+
},
1040+
},
1041+
'evaluator has correct resources, resolved against the provided base uri',
1042+
);
1043+
1044+
1045+
my $doc2 = $js->add_document('file:///usr/local/share/api.json' => $doc);
1046+
is($doc2, $doc, 'same document is added a second time');
1047+
1048+
cmp_deeply(
1049+
$js->{_resource_index},
1050+
{
1051+
%$resource_index, # original entries
1052+
1053+
'file:///usr/local/share/api.json' => {
1054+
path => '',
1055+
canonical_uri => str('file:///usr/local/share/staging/alpha.json'),
1056+
document => $doc,
1057+
%configs,
1058+
},
1059+
'file:///usr/local/share/staging/alpha.json' => {
1060+
path => '',
1061+
canonical_uri => str('file:///usr/local/share/staging/alpha.json'),
1062+
document => $doc,
1063+
%configs,
1064+
},
1065+
'file:///usr/local/share/staging/beta' => {
1066+
path => '/properties/foo',
1067+
canonical_uri => str('file:///usr/local/share/staging/beta'),
1068+
document => $doc,
1069+
%configs,
1070+
},
1071+
},
1072+
'document resources are added using new base, which appears in their canonical_uri values',
1073+
);
1074+
};
1075+
9841076
done_testing;

0 commit comments

Comments
 (0)