-
-
Notifications
You must be signed in to change notification settings - Fork 215
collapse all other-data-type format tests together #497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
646849e
to
6c9a1b4
Compare
tests/draft4/format.json
Outdated
"schema": {"format": "email"}, | ||
"description": "validation of string formats", | ||
"schema": { | ||
"allOf": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like the previous way more personally if I'm honest.
Or, I don't really have a strong opinion either way on putting these in one place or in each format, but I slightly prefer we don't complicate the schema -- i.e. use allOf
.
(I think basically the simpler each schema can be in the test suite, the better -- we don't mean to test interaction between allOf and format in these tests, so it's better if we don't use it, essentially)
Also, previously someone would get one test per format if you map each test case to a test case in your language's testing framework. But now it's one test for all formats, which likely will fail in a more obscure way if one format is broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency is good though -- e.g. it'd be nice certainly to have all of these kinds of tests looking the same way (using the same description, etc.).
6c9a1b4
to
e940330
Compare
Ok, I've kept the good bits of this PR - that is, normalizing all the tests, formatting and adding consistent data items. |
e940330
to
e000145
Compare
e000145
to
dadf73d
Compare
Thanks! This looks good to me now, though CI is failing, but it's because of the previous PR: #498 (comment) |
The generating script: ----8< perl >8---- use strict; use warnings; use JSON::PP (); use JSON::MaybeXS; use Path::Tiny; my %format_by_draft = ( draft3 => [ qw(email ip-address ipv6 host-name date-time regex date time color uri) ], draft4 => [ qw(email ipv4 ipv6 hostname date-time uri) ], draft6 => [ qw(email ipv4 ipv6 hostname date-time json-pointer uri uri-reference uri-template) ], draft7 => [ qw(email idn-email regex ipv4 ipv6 idn-hostname hostname date date-time time json-pointer relative-json-pointer iri iri-reference uri uri-reference uri-template) ], 'draft2019-09' => [ qw(email idn-email regex ipv4 ipv6 idn-hostname hostname date date-time time json-pointer relative-json-pointer iri iri-reference uri uri-reference uri-template uuid duration) ], 'draft2020-12' => [ qw(email idn-email regex ipv4 ipv6 idn-hostname hostname date date-time time json-pointer relative-json-pointer iri iri-reference uri uri-reference uri-template uuid duration) ], 'draft-future' => [ qw(email idn-email regex ipv4 ipv6 idn-hostname hostname date date-time time json-pointer relative-json-pointer iri iri-reference uri uri-reference uri-template uuid duration) ], ); my %type_to_data = ( integer => 12, float => 13.7, object => {}, array => [], boolean => JSON::PP::false, null => undef, ); my %format_string_data = ( email => '2962', 'ip-address' => '127.0.0.0.1', ipv6 => '12345::', 'host-name' => '-a-host-name-that-starts-with--', 'date-time' => '1990-02-31T15:59:60.123-08:00', regex => '^(abc]', date => '06/19/1963', time => '08:30:06 PST', uri => '//foo.bar/?baz=qux#quux', ipv4 => '127.0.0.0.1', hostname => '-a-host-name-that-starts-with--', 'json-pointer' => '/foo/bar~', 'uri-reference' => "\\\\WINDOWS\\fileshare", 'uri-template' => 'http://example.com/dictionary/{term:1}/{term', 'idn-email' => '2962', 'idn-hostname' => "〮실례.테스트", 'relative-json-pointer' => '/foo/bar', iri => 'http://2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'iri-reference' => "\\\\WINDOWS\\filëßåré", uuid => '2eb8aa08-aa98-11ea-b4aa-73b441d1638', duration => 'PT1D', ); my $encoder = JSON::MaybeXS->new(canonical => 1, pretty => 1, indent_length => 4); foreach my $draft (keys %format_by_draft) { my $data = [ map +{ description => $_.' format', schema => { format => $_ }, tests => [ (map +{ description => 'all string formats ignore '.$_.'s', data => $type_to_data{$_}, valid => JSON::PP::true, }, qw(integer float object array boolean null)), $draft !~ /^draft[467]/ && $format_string_data{$_} ? +{ description => 'invalid '.$_.' string is only an annotation by default', data => $format_string_data{$_}, valid => JSON::PP::true, } : (), ], }, @{$format_by_draft{$draft}} ]; my $str = $encoder->encode($data); $str =~ s/("data" : .+)(\n\s+)("description" : "[^"]+",)/$3$2$1/mg; $str =~ s/ : /: /g; $str =~ s/"schema": \{\n\s+("format": "[^"]+")\n\s+/"schema": { $1 /mg; path('tests', $draft, 'format.json')->spew_raw($str); }
dadf73d
to
ba1f1a7
Compare
lgtm now thanks for all the work! |
In older (pre-draft7) drafts, implementations are indeed free to treat format as an assertion by default. (ref #497 (comment))
This doesn't remove any checks, just folds them together consistently.