File: 462_bytes.rs

package info (click to toggle)
rust-ron 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 962 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#[test]
fn test_deserialise_byte_slice() {
    let val: &[u8] = &[0_u8, 1_u8, 2_u8, 3_u8];
    let ron = ron::to_string(val).unwrap();
    assert_eq!(ron, "[0,1,2,3]");

    // deserialising a byte slice from a byte sequence should fail
    //  with the error that a borrowed slice was expected but a byte
    //  buffer was provided
    // NOT with an expected string error, since the byte slice
    //  serialisation never serialises to a string
    assert_eq!(
        ron::from_str::<&[u8]>(&ron),
        Err(ron::error::SpannedError {
            code: ron::error::Error::InvalidValueForType {
                expected: String::from("a borrowed byte array"),
                found: String::from("the byte string b\"\\x00\\x01\\x02\\x03\""),
            },
            span: ron::error::Span {
                start: ron::error::Position { line: 1, col: 9 },
                end: ron::error::Position { line: 1, col: 10 },
            }
        })
    );
}