Skip to content

Commit

Permalink
try to guess what the test wanted to do
Browse files Browse the repository at this point in the history
  • Loading branch information
tarfu committed Nov 10, 2023
1 parent 366a0a4 commit d90bfd2
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl<'a> defmt::Format for SocketSet<'a> {

#[cfg(test)]
mod tests {
use core::any::Any;

Check warning on line 157 in src/set.rs

View workflow job for this annotation

GitHub Actions / Coverage

unused import: `core::any::Any`

Check warning on line 157 in src/set.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `core::any::Any`
use super::*;
use crate::{tcp, udp};

Expand Down Expand Up @@ -196,12 +197,35 @@ mod tests {
);
assert_eq!(set.iter().count(), 2);

// assert!(set.remove(SocketHandle(0)));
set.remove(SocketHandle(0));
assert_eq!(set.iter().count(), 1);
set.get::<udp::Socket>(SocketHandle(1));
}

#[test]
#[should_panic]
fn remove_non_existing_socket() {
let mut sockets = [SocketStorage::EMPTY; 2];
let mut set = SocketSet::new(&mut sockets);

let mut tcp_rx_buf = [0u8; 64];
let mut udp_rx_buf = [0u8; 48];

assert_eq!(
set.add(tcp::Socket::new(&mut tcp_rx_buf[..], &mut [][..])),
SocketHandle(0)
);
assert_eq!(set.iter().count(), 1);
assert_eq!(
set.add(udp::Socket::new(&mut udp_rx_buf[..], &mut [][..])),
SocketHandle(1)
);
assert_eq!(set.iter().count(), 2);

set.remove(SocketHandle(0));
set.get::<udp::Socket>(SocketHandle(0));

// assert!(set.get::<tcp::Socket>(SocketHandle(0)).is_err());

set.get::<udp::Socket>(SocketHandle(1));
}

#[test]
Expand Down Expand Up @@ -329,6 +353,8 @@ mod tests {
);
assert_eq!(set.iter().count(), 2);

set.remove(SocketHandle(0));

assert_eq!(set.iter().count(), 1);

set.get::<udp::Socket>(SocketHandle(1));
Expand Down Expand Up @@ -363,6 +389,6 @@ mod tests {

set.get::<tcp::Socket>(SocketHandle(0));

assert_eq!(set.iter().count(), 0);
assert_eq!(set.iter().count(), 2);
}
}

0 comments on commit d90bfd2

Please sign in to comment.