-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from chmp/fix/79-handle-unseen-fields-correctly
Fix/79 handle unseen fields correctly
- Loading branch information
Showing
7 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use super::macros::test_generic; | ||
|
||
test_generic!( | ||
fn declared_but_missing_fields() { | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
struct S { | ||
a: u8, | ||
} | ||
|
||
let items = [S { a: 0 }, S { a: 1 }]; | ||
|
||
let fields = vec![ | ||
Field::try_from(&GenericField::new("a", GenericDataType::U8, false)).unwrap(), | ||
Field::try_from(&GenericField::new("b", GenericDataType::U8, true)).unwrap(), | ||
]; | ||
|
||
let arrays = serialize_into_arrays(&fields, &items).unwrap(); | ||
|
||
assert_eq!(arrays.len(), 2); | ||
assert_eq!(arrays[0].len(), 2); | ||
assert_eq!(arrays[1].len(), 2); | ||
} | ||
); | ||
|
||
test_generic!( | ||
fn declared_but_missing_fields_non_nullable() { | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
struct S { | ||
a: u8, | ||
} | ||
|
||
let items = [S { a: 0 }, S { a: 1 }]; | ||
|
||
let fields = vec![ | ||
Field::try_from(&GenericField::new("a", GenericDataType::U8, false)).unwrap(), | ||
Field::try_from(&GenericField::new("b", GenericDataType::U8, false)).unwrap(), | ||
]; | ||
|
||
let Err(err) = serialize_into_arrays(&fields, &items) else { | ||
panic!("Expected error"); | ||
}; | ||
assert!( | ||
err.to_string() | ||
.contains("missing non-nullable field b in struct"), | ||
"unexpected error: {err}" | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ mod tuple; | |
mod r#union; | ||
mod utils; | ||
mod wrappers; | ||
|
||
mod issue_79; |