File: test_ascii_strings.rs

package info (click to toggle)
rust-borsh 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,824 kB
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 691 bytes parent folder | download | duplicates (14)
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
26
27
28
use alloc::string::ToString;
use borsh::from_slice;

#[test]
fn test_non_ascii() {
    let buf = borsh::to_vec(&[0xbf, 0xf3, 0xb3, 0x77][..]).unwrap();
    assert_eq!(
        from_slice::<ascii::AsciiString>(&buf)
            .unwrap_err()
            .to_string(),
        "the byte at index 0 is not ASCII"
    );

    let buf = borsh::to_vec("żółw").unwrap();
    assert_eq!(
        from_slice::<ascii::AsciiString>(&buf)
            .unwrap_err()
            .to_string(),
        "the byte at index 0 is not ASCII"
    );

    assert_eq!(
        from_slice::<ascii::AsciiChar>(&[0xbf])
            .unwrap_err()
            .to_string(),
        "not an ASCII character"
    );
}