create_iterative.rs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //! tests to prove that the iterative implementation works
  2. use anyhow::{Context, Result};
  3. use dioxus::{
  4. arena::SharedResources,
  5. diff::{CreateMeta, DiffMachine},
  6. prelude::*,
  7. scheduler::Mutations,
  8. DomEdit,
  9. };
  10. mod test_logging;
  11. use dioxus_core as dioxus;
  12. use dioxus_html as dioxus_elements;
  13. #[test]
  14. fn test_original_diff() {
  15. static App: FC<()> = |cx| {
  16. cx.render(rsx! {
  17. div {
  18. div {
  19. "Hello, world!"
  20. }
  21. }
  22. })
  23. };
  24. let mut dom = VirtualDom::new(App);
  25. let mutations = dom.rebuild().unwrap();
  26. dbg!(mutations);
  27. }
  28. #[async_std::test]
  29. async fn test_iterative_create() {
  30. static App: FC<()> = |cx| {
  31. cx.render(rsx! {
  32. div {
  33. div {
  34. "Hello, world!"
  35. div {
  36. div {
  37. Fragment {
  38. "hello"
  39. "world"
  40. }
  41. }
  42. }
  43. }
  44. }
  45. })
  46. };
  47. test_logging::set_up_logging();
  48. let mut dom = VirtualDom::new(App);
  49. let mutations = dom.rebuild_async().await.unwrap();
  50. dbg!(mutations);
  51. }
  52. #[async_std::test]
  53. async fn test_iterative_create_list() {
  54. static App: FC<()> = |cx| {
  55. cx.render(rsx! {
  56. {(0..3).map(|f| rsx!{ div {
  57. "hello"
  58. }})}
  59. })
  60. };
  61. test_logging::set_up_logging();
  62. let mut dom = VirtualDom::new(App);
  63. let mutations = dom.rebuild_async().await.unwrap();
  64. dbg!(mutations);
  65. }
  66. #[async_std::test]
  67. async fn test_iterative_create_simple() {
  68. static App: FC<()> = |cx| {
  69. cx.render(rsx! {
  70. div {}
  71. div {}
  72. div {}
  73. div {}
  74. })
  75. };
  76. test_logging::set_up_logging();
  77. let mut dom = VirtualDom::new(App);
  78. let mutations = dom.rebuild_async().await.unwrap();
  79. dbg!(mutations);
  80. }
  81. #[async_std::test]
  82. async fn test_iterative_create_components() {
  83. static App: FC<()> = |cx| {
  84. cx.render(rsx! {
  85. Child { "abc1" }
  86. Child { "abc2" }
  87. Child { "abc3" }
  88. })
  89. };
  90. static Child: FC<()> = |cx| {
  91. cx.render(rsx! {
  92. h1 {}
  93. div { {cx.children()} }
  94. p {}
  95. })
  96. };
  97. test_logging::set_up_logging();
  98. let mut dom = VirtualDom::new(App);
  99. let mutations = dom.rebuild_async().await.unwrap();
  100. dbg!(mutations);
  101. }