miri_simple.rs 2.7 KB

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