miri_simple.rs 2.7 KB

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