Skip to content

Commit b2043d1

Browse files
pull out a bit of common and boring data
1 parent 34121ce commit b2043d1

File tree

1 file changed

+39
-81
lines changed

1 file changed

+39
-81
lines changed

t/document.t

Lines changed: 39 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ use Helper;
1919
# spec version -> vocab classes
2020
my %vocabularies = unpairs(JSON::Schema::Modern->new->__all_metaschema_vocabulary_classes);
2121

22+
my %configs = (
23+
specification_version => 'draft2020-12',
24+
vocabularies => $vocabularies{'draft2020-12'},
25+
configs => {},
26+
);
27+
2228
subtest 'boolean document' => sub {
2329
cmp_deeply(
2430
JSON::Schema::Modern::Document->new(schema => false),
@@ -27,9 +33,7 @@ subtest 'boolean document' => sub {
2733
'' => {
2834
path => '',
2935
canonical_uri => str(''),
30-
specification_version => 'draft2020-12',
31-
vocabularies => ignore, # there are no keywords, so vocabularies doesn't matter
32-
configs => {},
36+
%configs,
3337
},
3438
],
3539
canonical_uri => [ str('') ],
@@ -59,9 +63,7 @@ subtest 'boolean document' => sub {
5963
'https://foo.com' => {
6064
path => '',
6165
canonical_uri => str('https://foo.com'),
62-
specification_version => 'draft2020-12',
63-
vocabularies => ignore, # there are no keywords, so vocabularies doesn't matter
64-
configs => {},
66+
%configs,
6567
},
6668
],
6769
canonical_uri => [ str('https://foo.com') ],
@@ -82,9 +84,7 @@ subtest 'object document' => sub {
8284
str($_//'') => {
8385
path => '',
8486
canonical_uri => str($_//''),
85-
specification_version => 'draft2020-12',
86-
vocabularies => $vocabularies{'draft2020-12'},
87-
configs => {},
87+
%configs,
8888
},
8989
],
9090
canonical_uri => [ str($_//'') ],
@@ -105,9 +105,7 @@ subtest 'object document' => sub {
105105
'https://foo.com' => {
106106
path => '',
107107
canonical_uri => str('https://foo.com'),
108-
specification_version => 'draft2020-12',
109-
vocabularies => $vocabularies{'draft2020-12'},
110-
configs => {},
108+
%configs,
111109
},
112110
],
113111
canonical_uri => [ str('https://foo.com') ],
@@ -127,9 +125,7 @@ subtest 'object document' => sub {
127125
'https://foo.com' => {
128126
path => '',
129127
canonical_uri => str('https://foo.com'),
130-
specification_version => 'draft2020-12',
131-
vocabularies => $vocabularies{'draft2020-12'},
132-
configs => {},
128+
%configs,
133129
},
134130
],
135131
canonical_uri => [ str('https://foo.com') ], # note canonical_uri has been overwritten
@@ -150,9 +146,7 @@ subtest 'object document' => sub {
150146
'https://bar.com' => {
151147
path => '',
152148
canonical_uri => str('https://bar.com'),
153-
specification_version => 'draft2020-12',
154-
vocabularies => $vocabularies{'draft2020-12'},
155-
configs => {},
149+
%configs,
156150
},
157151
],
158152
canonical_uri => [ str('https://bar.com') ], # note canonical_uri has been overwritten
@@ -174,9 +168,7 @@ subtest 'object document' => sub {
174168
'https://example.com' => {
175169
path => '',
176170
canonical_uri => str('https://example.com'),
177-
specification_version => 'draft2020-12',
178-
vocabularies => $vocabularies{'draft2020-12'},
179-
configs => {},
171+
%configs,
180172
},
181173
],
182174
),
@@ -193,9 +185,7 @@ subtest 'object document' => sub {
193185
'https://foo.com' => {
194186
path => '',
195187
canonical_uri => str('https://foo.com'),
196-
specification_version => 'draft2020-12',
197-
vocabularies => $vocabularies{'draft2020-12'},
198-
configs => {},
188+
%configs,
199189
},
200190
],
201191
canonical_uri => [ str('https://foo.com') ],
@@ -220,9 +210,7 @@ subtest 'object document' => sub {
220210
'https://bar.com' => {
221211
path => '',
222212
canonical_uri => str('https://bar.com'),
223-
specification_version => 'draft2020-12',
224-
vocabularies => $vocabularies{'draft2020-12'},
225-
configs => {},
213+
%configs,
226214
anchors => {
227215
my_anchor => {
228216
path => '/allOf/0',
@@ -233,9 +221,7 @@ subtest 'object document' => sub {
233221
'https://bar.com/x/y/z.json' => {
234222
path => '/allOf/1',
235223
canonical_uri => str('https://bar.com/x/y/z.json'),
236-
specification_version => 'draft2020-12',
237-
vocabularies => $vocabularies{'draft2020-12'},
238-
configs => {},
224+
%configs,
239225
},
240226
),
241227
canonical_uri => [ str('https://bar.com') ],
@@ -256,9 +242,7 @@ subtest 'object document' => sub {
256242
'https://my-base.com/relative' => {
257243
path => '',
258244
canonical_uri => str('https://my-base.com/relative'),
259-
specification_version => 'draft2020-12',
260-
vocabularies => $vocabularies{'draft2020-12'},
261-
configs => {},
245+
%configs,
262246
},
263247
],
264248
canonical_uri => [ str('https://my-base.com/relative') ],
@@ -282,16 +266,13 @@ subtest 'object document' => sub {
282266
listmethods(
283267
resource_index => unordered_pairs(
284268
'' => {
285-
path => '', canonical_uri => str(''), specification_version => 'draft2020-12',
286-
vocabularies => $vocabularies{'draft2020-12'},
287-
configs => {},
269+
path => '', canonical_uri => str(''),
270+
%configs,
288271
},
289272
'my_foo' => {
290273
path => '/$defs/foo',
291274
canonical_uri => str('my_foo'),
292-
specification_version => 'draft2020-12',
293-
vocabularies => $vocabularies{'draft2020-12'},
294-
configs => {},
275+
%configs,
295276
},
296277
),
297278
_entities => [ { map +($_ => 0), '', '/$defs/foo' } ],
@@ -313,16 +294,13 @@ subtest 'object document' => sub {
313294
listmethods(
314295
resource_index => unordered_pairs(
315296
'' => {
316-
path => '', canonical_uri => str(''), specification_version => 'draft2020-12',
317-
vocabularies => $vocabularies{'draft2020-12'},
318-
configs => {},
297+
path => '', canonical_uri => str(''),
298+
%configs,
319299
},
320300
'http://localhost:4242/my_foo' => {
321301
path => '/$defs/foo',
322302
canonical_uri => str('http://localhost:4242/my_foo'),
323-
specification_version => 'draft2020-12',
324-
vocabularies => $vocabularies{'draft2020-12'},
325-
configs => {},
303+
%configs,
326304
},
327305
),
328306
_entities => [ { map +($_ => 0), '', '/$defs/foo' } ],
@@ -339,9 +317,9 @@ subtest 'object document' => sub {
339317
listmethods(
340318
resource_index => [
341319
'' => {
342-
path => '', canonical_uri => str(''), specification_version => 'draft2020-12',
343-
vocabularies => $vocabularies{'draft2020-12'},
344-
configs => {},
320+
path => '',
321+
canonical_uri => str(''),
322+
%configs,
345323
anchors => {
346324
my_anchor => {
347325
path => '',
@@ -366,9 +344,7 @@ subtest 'object document' => sub {
366344
'https://example.com' => {
367345
path => '',
368346
canonical_uri => str('https://example.com'),
369-
specification_version => 'draft2020-12',
370-
vocabularies => $vocabularies{'draft2020-12'},
371-
configs => {},
347+
%configs,
372348
anchors => {
373349
my_anchor => {
374350
path => '',
@@ -393,9 +369,7 @@ subtest 'object document' => sub {
393369
'https://my-base.com' => {
394370
path => '',
395371
canonical_uri => str('https://my-base.com'),
396-
specification_version => 'draft2020-12',
397-
vocabularies => $vocabularies{'draft2020-12'},
398-
configs => {},
372+
%configs,
399373
anchors => {
400374
my_anchor => {
401375
path => '',
@@ -424,9 +398,7 @@ subtest 'object document' => sub {
424398
'https://my-base.com' => {
425399
path => '',
426400
canonical_uri => str('https://my-base.com'),
427-
specification_version => 'draft2020-12',
428-
vocabularies => $vocabularies{'draft2020-12'},
429-
configs => {},
401+
%configs,
430402
anchors => {
431403
my_anchor => {
432404
path => '/$defs/foo',
@@ -454,9 +426,9 @@ subtest '$id and $anchor as properties' => sub {
454426
listmethods(
455427
resource_index => [
456428
'' => {
457-
path => '', canonical_uri => str(''), specification_version => 'draft2020-12',
458-
vocabularies => $vocabularies{'draft2020-12'},
459-
configs => {},
429+
path => '',
430+
canonical_uri => str(''),
431+
%configs,
460432
},
461433
],
462434
_entities => [ { map +($_ => 0), '', '/properties/$id', '/properties/$anchor' } ],
@@ -487,9 +459,7 @@ subtest '$id with an empty fragment' => sub {
487459
'http://localhost:4242/my_foo' => {
488460
path => '/$defs/foo',
489461
canonical_uri => str('http://localhost:4242/my_foo'),
490-
specification_version => 'draft2020-12',
491-
vocabularies => $vocabularies{'draft2020-12'},
492-
configs => {},
462+
%configs,
493463
},
494464
),
495465
_entities => [ { map +($_ => 0), '', '/$defs/foo' } ],
@@ -668,9 +638,7 @@ subtest '$anchor and $id below an $id that is not at the document root' => sub {
668638
},
669639
'https://bar.com' => {
670640
path => '/allOf/0', canonical_uri => str('https://bar.com'),
671-
specification_version => 'draft2020-12',
672-
vocabularies => $vocabularies{'draft2020-12'},
673-
configs => {},
641+
%configs,
674642
anchors => {
675643
my_anchor => {
676644
path => '/allOf/0',
@@ -684,9 +652,7 @@ subtest '$anchor and $id below an $id that is not at the document root' => sub {
684652
},
685653
'https://bar.com/inner_id' => {
686654
path => '/allOf/0/not/not', canonical_uri => str('https://bar.com/inner_id'),
687-
specification_version => 'draft2020-12',
688-
vocabularies => $vocabularies{'draft2020-12'},
689-
configs => {},
655+
%configs,
690656
},
691657
),
692658
_entities => [ { map +($_ => 0), '', '/allOf/0', '/allOf/0/not', '/allOf/0/not/not' } ],
@@ -741,9 +707,7 @@ subtest 'JSON pointer and URI escaping' => sub {
741707
'http://localhost:4242/~username' => {
742708
path => '/$defs/foo/patternProperties/~0',
743709
canonical_uri => str('http://localhost:4242/~username'),
744-
specification_version => 'draft2020-12',
745-
vocabularies => $vocabularies{'draft2020-12'},
746-
configs => {},
710+
%configs,
747711
anchors => {
748712
tilde => {
749713
path => '/$defs/foo/patternProperties/~0/properties/~0~1',
@@ -754,9 +718,7 @@ subtest 'JSON pointer and URI escaping' => sub {
754718
'http://localhost:4242/my_slash' => {
755719
path => '/$defs/foo/patternProperties/~1',
756720
canonical_uri => str('http://localhost:4242/my_slash'),
757-
specification_version => 'draft2020-12',
758-
vocabularies => $vocabularies{'draft2020-12'},
759-
configs => {},
721+
%configs,
760722
anchors => {
761723
slash => {
762724
path => '/$defs/foo/patternProperties/~1/properties/~0~1',
@@ -767,9 +729,7 @@ subtest 'JSON pointer and URI escaping' => sub {
767729
'http://localhost:4242/~username/my_slash' => {
768730
path => '/$defs/foo/patternProperties/[~0~1]',
769731
canonical_uri => str('http://localhost:4242/~username/my_slash'),
770-
specification_version => 'draft2020-12',
771-
vocabularies => $vocabularies{'draft2020-12'},
772-
configs => {},
732+
%configs,
773733
anchors => {
774734
tildeslash => {
775735
path => '/$defs/foo/patternProperties/[~0~1]/properties/~0~1',
@@ -923,9 +883,7 @@ subtest 'create document with explicit canonical_uri set to the same as root $id
923883
'https://foo.com/x/y/z' => {
924884
path => '',
925885
canonical_uri => str('https://foo.com/x/y/z'),
926-
specification_version => 'draft2020-12',
927-
vocabularies => $vocabularies{'draft2020-12'},
928-
configs => {},
886+
%configs,
929887
},
930888
],
931889
canonical_uri => [ str('https://foo.com/x/y/z') ],

0 commit comments

Comments
 (0)