Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ouertani committed Oct 24, 2024
1 parent 292faa5 commit 1c4fa15
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ impl GeneratorBuilder {
/// Adds support to derive custom macros.
///
/// Applies to record structs.
pub fn extra_derives(mut self, extra_derives: Vec<String>) -> GeneratorBuilder {
self.extra_derives = extra_derives;
pub fn extra_derives(mut self, extra_derives: Vec<&str>) -> GeneratorBuilder {
self.extra_derives = extra_derives.into_iter().map(String::from).collect();
self
}

Expand Down
2 changes: 1 addition & 1 deletion src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const RECORD_TEMPLATE: &str = r#"
/// {{ doc_line }}
{%- endfor %}
{%- endif %}
#[derive(Debug, PartialEq{%- if is_eq_derivable %}, Eq{%- endif %}, Clone, serde::Deserialize, serde::Serialize{%- if derive_builders %}, derive_builder::Builder {%- endif %}{%- if derive_schemas %}, apache_avro::AvroSchema {%- endif %} {%- if extra_derives %},{{ extra_derives}} {%- endif %})]
#[derive(Debug, PartialEq{%- if is_eq_derivable %}, Eq{%- endif %}, Clone, serde::Deserialize, serde::Serialize{%- if derive_builders %}, derive_builder::Builder {%- endif %}{%- if derive_schemas %}, apache_avro::AvroSchema {%- endif %} {%- if extra_derives %}, {{ extra_derives}} {%- endif %})]
{%- if derive_builders %}
#[builder(setter(into))]
{%- endif %}
Expand Down
7 changes: 2 additions & 5 deletions tests/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fn gen_one_extra_derives() {
validate_generation(
"one_extra_derive",
Generator::builder()
.extra_derives(vec!["std::fmt::Display".to_string()])
.extra_derives(vec!["std::fmt::Display"])
.build()
.unwrap(),
);
Expand All @@ -247,10 +247,7 @@ fn gen_two_extra_derives() {
validate_generation(
"two_extra_derives",
Generator::builder()
.extra_derives(vec![
"std::fmt::Display".to_string(),
"std::string::ToString".to_string(),
])
.extra_derives(vec!["std::fmt::Display", "std::string::ToString"])
.build()
.unwrap(),
);
Expand Down
2 changes: 1 addition & 1 deletion tests/schemas/one_extra_derive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize,std::fmt::Display)]
#[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize, std::fmt::Display)]
pub struct Test {
#[serde(default = "default_test_a")]
pub a: i64,
Expand Down
2 changes: 1 addition & 1 deletion tests/schemas/two_extra_derives.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize,std::fmt::Display, std::string::ToString)]
#[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize, std::fmt::Display, std::string::ToString)]
pub struct Test {
#[serde(default = "default_test_a")]
pub a: i64,
Expand Down

0 comments on commit 1c4fa15

Please sign in to comment.