Kriskras99 commented on code in PR #571:
URL: https://github.com/apache/avro-rs/pull/571#discussion_r3579793733
##########
avro_derive/src/implementation.rs:
##########
@@ -77,15 +81,46 @@ impl Implementation {
schema_expr: TokenStream,
record_fields_expr: Option<TokenStream>,
field_default_expr: Option<TokenStream>,
+ tests: bool,
) -> Implementation {
- Self {
+ let mut this = Self {
ident,
generics,
schema_expr,
record_fields_expr: record_fields_expr
.unwrap_or_else(|| quote! { ::std::option::Option::None }),
field_default_expr: field_default_expr
.unwrap_or_else(|| quote! { ::std::option::Option::None }),
+ tests: tests.then(Vec::new),
+ };
+
+ this.add_schema_test();
+
+ this
+ }
+
+ pub fn add_test(&mut self, test: Test) {
+ if let Some(tests) = &mut self.tests {
+ tests.push(test);
+ }
+ }
+
+ fn add_schema_test(&mut self) {
+ // Only add the schema test if there are no generics to deal with. I
think it should be possible
+ // to be able to generate the test if there are only lifetimes, but
that needs more experimentation.
+ if self.generics.lifetimes().count() == 0
+ && self.generics.type_params().count() == 0
+ && self.generics.const_params().count() == 0
+ {
+ let ident = &self.ident;
+ self.add_test(Test {
+ name: "schema".to_string(),
Review Comment:
I think especially point 4 is a good point, so let's close this for now.
(1 and 3 are to allow generating other kinds of tests, 2 is so that the user
gets some feedback when the test fails).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]