1 | // SPDX-License-Identifier: Apache-2.0 |
2 | |
3 | #![cfg (all(feature = "serde" , not(feature = "std" )))] |
4 | #![no_std ] |
5 | |
6 | extern crate alloc; |
7 | |
8 | use alloc::vec::Vec; |
9 | |
10 | use ciborium::{de::from_reader, ser::into_writer}; |
11 | |
12 | #[test] |
13 | fn decode() { |
14 | assert_eq!(from_reader::<u8, &[u8]>(&[7u8][..]).unwrap(), 7); |
15 | } |
16 | |
17 | #[test] |
18 | fn eof() { |
19 | from_reader::<u8, &[u8]>(&[]).unwrap_err(); |
20 | } |
21 | |
22 | #[test] |
23 | fn encode_slice() { |
24 | let mut buffer = [0u8; 1]; |
25 | into_writer(&3u8, &mut buffer[..]).unwrap(); |
26 | assert_eq!(buffer[0], 3); |
27 | } |
28 | |
29 | #[test] |
30 | fn encode_vec() { |
31 | let mut buffer = Vec::with_capacity(1); |
32 | into_writer(&3u8, &mut buffer).unwrap(); |
33 | assert_eq!(buffer[0], 3); |
34 | } |
35 | |
36 | #[test] |
37 | fn oos() { |
38 | into_writer(&3u8, &mut [][..]).unwrap_err(); |
39 | } |
40 | |