miri_simple.rs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. use dioxus::prelude::*;
  2. #[test]
  3. fn app_drops() {
  4. #[component]
  5. fn App(cx: Scope) -> Element {
  6. render! { div {} }
  7. }
  8. let mut dom = VirtualDom::new(App);
  9. _ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
  10. dom.mark_dirty(ScopeId::ROOT);
  11. _ = dom.render_immediate_to_vec();
  12. }
  13. #[test]
  14. fn hooks_drop() {
  15. #[component]
  16. fn App(cx: Scope) -> Element {
  17. cx.use_hook(|| String::from("asd"));
  18. cx.use_hook(|| String::from("asd"));
  19. cx.use_hook(|| String::from("asd"));
  20. cx.use_hook(|| String::from("asd"));
  21. render! { div {} }
  22. }
  23. let mut dom = VirtualDom::new(App);
  24. _ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
  25. dom.mark_dirty(ScopeId::ROOT);
  26. _ = dom.render_immediate_to_vec();
  27. }
  28. #[test]
  29. fn contexts_drop() {
  30. #[component]
  31. fn App(cx: Scope) -> Element {
  32. cx.provide_context(String::from("asd"));
  33. render! {
  34. div { ChildComp {} }
  35. }
  36. }
  37. #[component]
  38. fn ChildComp(cx: Scope) -> Element {
  39. let el = cx.consume_context::<String>().unwrap();
  40. render! { div { "hello {el}" } }
  41. }
  42. let mut dom = VirtualDom::new(App);
  43. _ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
  44. dom.mark_dirty(ScopeId::ROOT);
  45. _ = dom.render_immediate_to_vec();
  46. }
  47. #[test]
  48. fn tasks_drop() {
  49. #[component]
  50. fn App(cx: Scope) -> Element {
  51. cx.spawn(async {
  52. // tokio::time::sleep(std::time::Duration::from_millis(100000)).await;
  53. });
  54. render! { div {} }
  55. }
  56. let mut dom = VirtualDom::new(App);
  57. _ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
  58. dom.mark_dirty(ScopeId::ROOT);
  59. _ = dom.render_immediate_to_vec();
  60. }
  61. #[test]
  62. fn root_props_drop() {
  63. struct RootProps(String);
  64. let mut dom = VirtualDom::new_with_props(
  65. |cx| render!( div { "{cx.props.0}" } ),
  66. RootProps("asdasd".to_string()),
  67. );
  68. _ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
  69. dom.mark_dirty(ScopeId::ROOT);
  70. _ = dom.render_immediate_to_vec();
  71. }
  72. #[test]
  73. fn diffing_drops_old() {
  74. #[component]
  75. fn App(cx: Scope) -> Element {
  76. render! {
  77. div {
  78. match generation() % 2 {
  79. 0 => render!( ChildComp1 { name: "asdasd".to_string() }),
  80. 1 => render!( ChildComp2 { name: "asdasd".to_string() }),
  81. _ => todo!()
  82. }
  83. }
  84. }
  85. }
  86. #[component]
  87. fn ChildComp1(cx: Scope, name: String) -> Element {
  88. render! {"Hello {name}"}
  89. }
  90. #[component]
  91. fn ChildComp2(cx: Scope, name: String) -> Element {
  92. render! {"Goodbye {name}"}
  93. }
  94. let mut dom = VirtualDom::new(App);
  95. _ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
  96. dom.mark_dirty(ScopeId::ROOT);
  97. _ = dom.render_immediate_to_vec();
  98. }