-
Notifications
You must be signed in to change notification settings - Fork 0
v1.1.0 with added functions & bug fixes #21
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -132,6 +132,34 @@ mod tests { | |||||
| impl_test_x!(test_byte_array, [0x41 as u8, 0x42 as u8, 0x43 as u8]); | ||||||
| impl_test_x!(test_array, [0x41, 0x42, 0x43]); | ||||||
|
|
||||||
| #[test] | ||||||
| fn test_borrowed_bytes() { | ||||||
| // The data must live as long as the deserialized reference. | ||||||
| let value: &[u8] = &[0x41, 0x42, 0x43]; | ||||||
| let serialized = Serializer::to_bytes(&value, false).unwrap(); | ||||||
|
|
||||||
| // Make the test function generic over the lifetime. | ||||||
| fn roundtrip<'de>(input: &'de [u8]) { | ||||||
| let deserialized: &'de [u8] = Deserializer::from_bytes(&input, false).unwrap(); | ||||||
| assert_eq!(&input[1..], deserialized); | ||||||
| } | ||||||
|
|
||||||
| roundtrip(&serialized); | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn test_serde_bytes_bytes() { | ||||||
| use serde_bytes::Bytes; | ||||||
| let data = [0x41, 0x42, 0x43]; | ||||||
| let value: &Bytes = Bytes::new(&data); | ||||||
|
|
||||||
| let serialized = Serializer::to_bytes(&value, false).unwrap(); | ||||||
| let deserialized: &Bytes = | ||||||
| Deserializer::from_bytes(Bytes::new(&serialized), false).unwrap(); | ||||||
|
||||||
| Deserializer::from_bytes(Bytes::new(&serialized), false).unwrap(); | |
| Deserializer::from_bytes(&serialized, false).unwrap(); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -130,8 +130,12 @@ impl<'a> ser::Serializer for &'a mut Serializer { | |||||
| self.serialize_vec(v.as_bytes().to_vec()) | ||||||
| } | ||||||
|
|
||||||
| fn serialize_bytes(self, _v: &[u8]) -> Result<Self::Ok> { | ||||||
| unimplemented!() | ||||||
| fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok> { | ||||||
| if v.len() > 0 { | ||||||
|
||||||
| if v.len() > 0 { | |
| if !v.is_empty() { |
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.
The assertion compares
&input[1..](skipping the first byte) withdeserialized, but the test should compare the originalvaluewithdeserialized. This appears to be accounting for a length prefix, but the logic is unclear and may not be testing the correct behavior.