mirror of https://git.sr.ht/~stygianentity/bincode
Added test case for a borrowed str (#441)
This commit is contained in:
parent
4be23b88de
commit
7cb10d4ab3
|
|
@ -17,7 +17,7 @@ pub struct Test2<T: Decode> {
|
||||||
c: u32,
|
c: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(bincode::BorrowDecode, PartialEq, Debug, Eq)]
|
#[derive(bincode::BorrowDecode, bincode::Encode, PartialEq, Debug, Eq)]
|
||||||
pub struct Test3<'a> {
|
pub struct Test3<'a> {
|
||||||
a: &'a str,
|
a: &'a str,
|
||||||
b: u32,
|
b: u32,
|
||||||
|
|
@ -55,7 +55,6 @@ fn test_encode() {
|
||||||
assert_eq!(&slice[..bytes_written], &[10, 10, 20]);
|
assert_eq!(&slice[..bytes_written], &[10, 10, 20]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_decode() {
|
fn test_decode() {
|
||||||
let start = Test2 {
|
let start = Test2 {
|
||||||
|
|
@ -64,11 +63,24 @@ fn test_decode() {
|
||||||
c: 1024u32,
|
c: 1024u32,
|
||||||
};
|
};
|
||||||
let slice = [5, 10, 251, 0, 4];
|
let slice = [5, 10, 251, 0, 4];
|
||||||
let result: Test2<u32> =
|
let result: Test2<u32> = bincode::decode_from_slice(&slice, Configuration::standard()).unwrap();
|
||||||
bincode::decode_from_std_read(&mut slice.as_ref(), Configuration::standard()).unwrap();
|
|
||||||
assert_eq!(result, start);
|
assert_eq!(result, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_encode_decode_str() {
|
||||||
|
let start = Test3 {
|
||||||
|
a: "Foo bar",
|
||||||
|
b: 10u32,
|
||||||
|
c: 1024u32,
|
||||||
|
};
|
||||||
|
let mut slice = [0u8; 100];
|
||||||
|
|
||||||
|
let len = bincode::encode_into_slice(&start, &mut slice, Configuration::standard()).unwrap();
|
||||||
|
let end: Test3 = bincode::decode_from_slice(&slice[..len], Configuration::standard()).unwrap();
|
||||||
|
assert_eq!(end, start);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_encode_tuple() {
|
fn test_encode_tuple() {
|
||||||
let start = TestTupleStruct(5, 10, 1024);
|
let start = TestTupleStruct(5, 10, 1024);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue