Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
slanterns committed Jul 27, 2024
1 parent 2d7426e commit 3f6e6bc
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions library/core/tests/waker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::ptr;
use std::task::{RawWaker, RawWakerVTable, Waker};
use core::future::{ready, Future};
use core::pin::Pin;
use core::ptr;
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};

#[test]
fn test_waker_getters() {
Expand All @@ -20,3 +22,27 @@ static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
|_| {},
|_| {},
);


const NOP_RAWWAKER: RawWaker = {
fn nop(_: *const ()) {}
const VTAB: RawWakerVTable = RawWakerVTable::new(|_| NOP_RAWWAKER, nop, nop, nop);
RawWaker::new(&() as *const (), &VTAB)
};

const NOP_WAKER: &Waker = &unsafe { Waker::from_raw(NOP_RAWWAKER) };

const NOP_CONTEXT: Context<'static> = Context::from_waker(NOP_WAKER);

fn poll_once<T, F>(f: &mut F) -> Poll<T>
where
F: Future<Output = T> + ?Sized + Unpin,
{
let mut cx = NOP_CONTEXT;
Pin::new(f).as_mut().poll(&mut cx)
}

#[test]
fn test_const_waker() {
assert_eq!(poll_once(&mut ready(1)), Poll::Ready(1));
}

0 comments on commit 3f6e6bc

Please sign in to comment.