2022-11-29 21:31:04 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_drops() {
|
2024-01-11 21:23:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! { div {} }
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 21:23:37 +00:00
|
|
|
let mut dom = VirtualDom::new(app);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-15 17:06:27 +00:00
|
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
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() {
|
2024-01-11 21:23:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-15 15:05:46 +00:00
|
|
|
use_hook(|| String::from("asd"));
|
|
|
|
use_hook(|| String::from("asd"));
|
|
|
|
use_hook(|| String::from("asd"));
|
|
|
|
use_hook(|| String::from("asd"));
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! { div {} }
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 21:23:37 +00:00
|
|
|
let mut dom = VirtualDom::new(app);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-15 17:06:27 +00:00
|
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
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() {
|
2024-01-11 21:23:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-11 21:18:11 +00:00
|
|
|
provide_context(String::from("asd"));
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {
|
2024-01-11 01:21:15 +00:00
|
|
|
div { ChildComp {} }
|
|
|
|
}
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 17:11:44 +00:00
|
|
|
fn ChildComp() -> Element {
|
2024-01-16 21:51:02 +00:00
|
|
|
let el = consume_context::<String>();
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! { div { "hello {el}" } }
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 21:23:37 +00:00
|
|
|
let mut dom = VirtualDom::new(app);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-15 17:06:27 +00:00
|
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
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() {
|
2024-01-11 21:23:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-11 21:18:11 +00:00
|
|
|
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-16 19:18:46 +00:00
|
|
|
rsx! { div {} }
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 21:23:37 +00:00
|
|
|
let mut dom = VirtualDom::new(app);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
2024-01-15 17:06:27 +00:00
|
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
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() {
|
2024-01-11 18:40:36 +00:00
|
|
|
#[derive(Clone)]
|
2022-11-29 21:31:04 +00:00
|
|
|
struct RootProps(String);
|
|
|
|
|
|
|
|
let mut dom = VirtualDom::new_with_props(
|
2024-01-16 21:51:02 +00:00
|
|
|
|cx: RootProps| rsx!( div { "{cx.0}" } ),
|
2022-11-29 21:31:04 +00:00
|
|
|
RootProps("asdasd".to_string()),
|
|
|
|
);
|
|
|
|
|
2024-01-15 17:06:27 +00:00
|
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
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() {
|
2024-01-11 21:23:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {
|
2022-11-29 21:31:04 +00:00
|
|
|
div {
|
2024-01-11 01:21:15 +00:00
|
|
|
match generation() % 2 {
|
2024-01-16 19:18:46 +00:00
|
|
|
0 => rsx!( ChildComp1 { name: "asdasd".to_string() }),
|
|
|
|
1 => rsx!( 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
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
2024-01-11 17:11:44 +00:00
|
|
|
fn ChildComp1(name: String) -> Element {
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {"Hello {name}"}
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
2024-01-11 17:11:44 +00:00
|
|
|
fn ChildComp2(name: String) -> Element {
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {"Goodbye {name}"}
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 21:23:37 +00:00
|
|
|
let mut dom = VirtualDom::new(app);
|
2024-01-15 17:06:27 +00:00
|
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2023-08-25 13:31:23 +00:00
|
|
|
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
|
|
|
}
|
2024-01-22 15:08:29 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hooks_drop_before_contexts() {
|
|
|
|
fn app() -> Element {
|
|
|
|
provide_context(123i32);
|
|
|
|
use_hook(|| {
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct ReadsContextOnDrop;
|
|
|
|
|
|
|
|
impl Drop for ReadsContextOnDrop {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
let _ = consume_context::<i32>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
rsx! { div {} }
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut dom = VirtualDom::new(app);
|
|
|
|
|
|
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
|
|
_ = dom.render_immediate_to_vec();
|
|
|
|
}
|