Nothing to see here, move along meow
1use lancer_core::line_buf::LineBuf;
2use proptest::prelude::*;
3
4#[test]
5fn new_is_empty() {
6 let buf: LineBuf<64> = LineBuf::new();
7 assert!(buf.is_empty());
8 assert_eq!(buf.len(), 0);
9 assert_eq!(buf.as_bytes(), &[]);
10}
11
12#[test]
13fn pop_on_empty_returns_false() {
14 let mut buf: LineBuf<64> = LineBuf::new();
15 assert!(!buf.pop());
16}
17
18#[test]
19fn push_beyond_capacity_returns_false() {
20 let mut buf: LineBuf<2> = LineBuf::new();
21 assert!(buf.push(b'a'));
22 assert!(buf.push(b'b'));
23 assert!(!buf.push(b'c'));
24 assert_eq!(buf.len(), 2);
25}
26
27#[test]
28fn clear_resets() {
29 let mut buf: LineBuf<64> = LineBuf::new();
30 buf.push(b'x');
31 buf.push(b'y');
32 buf.clear();
33 assert!(buf.is_empty());
34 assert_eq!(buf.as_bytes(), &[]);
35}
36
37proptest! {
38 #[test]
39 fn push_round_trip(bytes in proptest::collection::vec(any::<u8>(), 0..=64)) {
40 let mut buf: LineBuf<64> = LineBuf::new();
41 bytes.iter().for_each(|&b| { buf.push(b); });
42 prop_assert_eq!(buf.as_bytes(), &bytes[..]);
43 prop_assert_eq!(buf.len(), bytes.len());
44 }
45
46 #[test]
47 fn push_capped_at_capacity(bytes in proptest::collection::vec(any::<u8>(), 0..=128)) {
48 let mut buf: LineBuf<32> = LineBuf::new();
49 let accepted = bytes.iter().filter(|&&b| buf.push(b)).count();
50 let expected = if bytes.len() > 32 { 32 } else { bytes.len() };
51 prop_assert_eq!(accepted, expected);
52 prop_assert_eq!(buf.len(), expected);
53 prop_assert_eq!(buf.as_bytes(), &bytes[..expected]);
54 }
55
56 #[test]
57 fn pop_reduces_length(bytes in proptest::collection::vec(any::<u8>(), 1..=32)) {
58 let mut buf: LineBuf<32> = LineBuf::new();
59 bytes.iter().for_each(|&b| { buf.push(b); });
60 assert!(buf.pop());
61 prop_assert_eq!(buf.len(), bytes.len() - 1);
62 prop_assert_eq!(buf.as_bytes(), &bytes[..bytes.len() - 1]);
63 }
64}