Debian Codegraph @

tests/462_bytes.rs

raw symbols SCIP
1 #[test]
2 fn test_deserialise_byte_slice() {
3 let val: &[u8] = &[0_u8, 1_u8, 2_u8, 3_u8];
4 let ron = ron::to_string(val).unwrap();
5 assert_eq!(ron, "[0,1,2,3]");
6
7 // deserialising a byte slice from a byte sequence should fail
8 // with the error that a borrowed slice was expected but a byte
9 // buffer was provided
10 // NOT with an expected string error, since the byte slice
11 // serialisation never serialises to a string
12 assert_eq!(
13 ron::from_str::<&[u8]>(&ron),
14 Err(ron::error::SpannedError {
15 code: ron::error::Error::InvalidValueForType {
16 expected: String::from("a borrowed byte array"),
17 found: String::from("the byte string b\"\\x00\\x01\\x02\\x03\""),
18 },
19 span: ron::error::Span {
20 start: ron::error::Position { line: 1, col: 9 },
21 end: ron::error::Position { line: 1, col: 10 },
22 }
23 })
24 );
25 }