Skip to content

Commit

Permalink
add a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccbrown committed Sep 24, 2024
1 parent 9c65afd commit 6911798
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/iocraft-macros/tests/with_layout_style_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ struct MyPropsWithTypeGeneric<T> {
foo: Option<T>,
}

#[with_layout_style_props]
#[derive(Default, Props)]
struct MyPropsWithConstParam<const N: usize> {
foo: Option<[u8; N]>,
}

#[test]
fn layout_style_props() {
let props: MyProps = Default::default();
Expand All @@ -32,4 +38,8 @@ fn layout_style_props() {
let props: MyPropsWithTypeGeneric<String> = Default::default();
assert_eq!(props.foo, None);
assert_eq!(props.display, Display::DEFAULT);

let props: MyPropsWithConstParam<1> = Default::default();
assert_eq!(props.foo, None);
assert_eq!(props.display, Display::DEFAULT);
}
27 changes: 24 additions & 3 deletions packages/iocraft/src/hooks/use_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,49 @@ impl UseOutputImpl {
#[cfg(test)]
mod tests {
use super::*;
use crate::prelude::*;
use futures::task::noop_waker;
use macro_rules_attribute::apply;
use smol_macros::test;

#[test]
fn test_use_output_polling() {
let mut use_output = UseOutputImpl::default();
assert_eq!(
Pin::new(&mut use_output).poll_change(&mut Context::from_waker(&noop_waker())),
Pin::new(&mut use_output)
.poll_change(&mut std::task::Context::from_waker(&noop_waker())),
Poll::Pending
);

let stdout = use_output.use_stdout();
stdout.println("Hello, world!");
assert_eq!(
Pin::new(&mut use_output).poll_change(&mut Context::from_waker(&noop_waker())),
Pin::new(&mut use_output)
.poll_change(&mut std::task::Context::from_waker(&noop_waker())),
Poll::Ready(())
);

let stderr = use_output.use_stderr();
stderr.println("Hello, error!");
assert_eq!(
Pin::new(&mut use_output).poll_change(&mut Context::from_waker(&noop_waker())),
Pin::new(&mut use_output)
.poll_change(&mut std::task::Context::from_waker(&noop_waker())),
Poll::Ready(())
);
}

#[component]
fn MyComponent(mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
let mut system = hooks.use_context_mut::<SystemContext>();
let (stdout, stderr) = hooks.use_output();
stdout.println("Hello, world!");
stderr.println("Hello, error!");
system.exit();
element!(Box)
}

#[apply(test!)]
async fn test_use_output() {
element!(MyComponent).render_loop().await.unwrap();
}
}

0 comments on commit 6911798

Please sign in to comment.