dioxus/packages/core/tests/miri_simple.rs

119 lines
2.7 KiB
Rust
Raw Normal View History

2022-11-29 21:31:04 +00:00
use dioxus::prelude::*;
#[test]
fn app_drops() {
fn App() -> Element {
2024-01-11 01:21:15 +00:00
render! { div {} }
2022-11-29 21:31:04 +00:00
}
let mut dom = VirtualDom::new(App);
2022-11-29 21:31:04 +00:00
2024-01-11 01:21:15 +00:00
_ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
dom.mark_dirty(ScopeId::ROOT);
2024-01-11 01:21:15 +00:00
_ = dom.render_immediate_to_vec();
2022-11-29 21:31:04 +00:00
}
#[test]
fn hooks_drop() {
fn App() -> Element {
2022-11-29 21:31:04 +00:00
cx.use_hook(|| String::from("asd"));
cx.use_hook(|| String::from("asd"));
cx.use_hook(|| String::from("asd"));
cx.use_hook(|| String::from("asd"));
2024-01-11 01:21:15 +00:00
render! { div {} }
2022-11-29 21:31:04 +00:00
}
let mut dom = VirtualDom::new(App);
2022-11-29 21:31:04 +00:00
2024-01-11 01:21:15 +00:00
_ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
dom.mark_dirty(ScopeId::ROOT);
2024-01-11 01:21:15 +00:00
_ = dom.render_immediate_to_vec();
2022-11-29 21:31:04 +00:00
}
#[test]
fn contexts_drop() {
fn App() -> Element {
2022-11-29 21:31:04 +00:00
cx.provide_context(String::from("asd"));
2024-01-11 01:21:15 +00:00
render! {
div { ChildComp {} }
}
2022-11-29 21:31:04 +00:00
}
#[component]
2024-01-11 17:11:44 +00:00
fn ChildComp() -> Element {
2022-11-29 21:31:04 +00:00
let el = cx.consume_context::<String>().unwrap();
2024-01-11 01:21:15 +00:00
render! { div { "hello {el}" } }
2022-11-29 21:31:04 +00:00
}
let mut dom = VirtualDom::new(App);
2022-11-29 21:31:04 +00:00
2024-01-11 01:21:15 +00:00
_ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
dom.mark_dirty(ScopeId::ROOT);
2024-01-11 01:21:15 +00:00
_ = dom.render_immediate_to_vec();
2022-11-29 21:31:04 +00:00
}
2022-12-17 04:26:04 +00:00
#[test]
fn tasks_drop() {
fn App() -> Element {
2022-11-29 21:31:04 +00:00
cx.spawn(async {
2022-12-17 04:26:04 +00:00
// tokio::time::sleep(std::time::Duration::from_millis(100000)).await;
2022-11-29 21:31:04 +00:00
});
2024-01-11 01:21:15 +00:00
render! { div {} }
2022-11-29 21:31:04 +00:00
}
let mut dom = VirtualDom::new(App);
2022-11-29 21:31:04 +00:00
2024-01-11 01:21:15 +00:00
_ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
dom.mark_dirty(ScopeId::ROOT);
2024-01-11 01:21:15 +00:00
_ = dom.render_immediate_to_vec();
2022-11-29 21:31:04 +00:00
}
#[test]
fn root_props_drop() {
struct RootProps(String);
let mut dom = VirtualDom::new_with_props(
2024-01-11 17:11:44 +00:00
|cx| render!( div { "{cx.0}" } ),
2022-11-29 21:31:04 +00:00
RootProps("asdasd".to_string()),
);
2024-01-11 01:21:15 +00:00
_ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
dom.mark_dirty(ScopeId::ROOT);
2024-01-11 01:21:15 +00:00
_ = dom.render_immediate_to_vec();
2022-11-29 21:31:04 +00:00
}
#[test]
fn diffing_drops_old() {
fn App() -> Element {
2024-01-11 01:21:15 +00:00
render! {
2022-11-29 21:31:04 +00:00
div {
2024-01-11 01:21:15 +00:00
match generation() % 2 {
0 => render!( ChildComp1 { name: "asdasd".to_string() }),
1 => render!( ChildComp2 { name: "asdasd".to_string() }),
2022-11-29 21:31:04 +00:00
_ => todo!()
}
}
2024-01-11 01:21:15 +00:00
}
2022-11-29 21:31:04 +00:00
}
#[component]
2024-01-11 17:11:44 +00:00
fn ChildComp1(name: String) -> Element {
2024-01-11 01:21:15 +00:00
render! {"Hello {name}"}
2022-11-29 21:31:04 +00:00
}
#[component]
2024-01-11 17:11:44 +00:00
fn ChildComp2(name: String) -> Element {
2024-01-11 01:21:15 +00:00
render! {"Goodbye {name}"}
2022-11-29 21:31:04 +00:00
}
let mut dom = VirtualDom::new(App);
2024-01-11 01:21:15 +00:00
_ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
dom.mark_dirty(ScopeId::ROOT);
2022-11-29 21:31:04 +00:00
2024-01-11 01:21:15 +00:00
_ = dom.render_immediate_to_vec();
2022-11-29 21:31:04 +00:00
}