simple.rs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. use html_parser::Dom;
  2. #[test]
  3. fn simple_elements() {
  4. let html = r#"
  5. <div>
  6. <div class="asd">hello world!</div>
  7. <div id="asd">hello world!</div>
  8. <div id="asd">hello world!</div>
  9. <div for="asd">hello world!</div>
  10. <div async="asd">hello world!</div>
  11. </div>
  12. "#
  13. .trim();
  14. let dom = Dom::parse(html).unwrap();
  15. let body = dioxus_rsx_rosetta::rsx_from_html(&dom);
  16. let out = dioxus_autofmt::write_block_out(&body).unwrap();
  17. let expected = r#"
  18. div {
  19. div { class: "asd", "hello world!" }
  20. div { id: "asd", "hello world!" }
  21. div { id: "asd", "hello world!" }
  22. div { r#for: "asd", "hello world!" }
  23. div { r#async: "asd", "hello world!" }
  24. }"#;
  25. pretty_assertions::assert_eq!(&out, &expected);
  26. }
  27. #[test]
  28. fn deeply_nested() {
  29. let html = r#"
  30. <div>
  31. <div class="asd">
  32. <div class="asd">
  33. <div class="asd">
  34. <div class="asd">
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. "#
  41. .trim();
  42. let dom = Dom::parse(html).unwrap();
  43. let body = dioxus_rsx_rosetta::rsx_from_html(&dom);
  44. let out = dioxus_autofmt::write_block_out(&body).unwrap();
  45. let expected = r#"
  46. div {
  47. div { class: "asd",
  48. div { class: "asd",
  49. div { class: "asd",
  50. div { class: "asd" }
  51. }
  52. }
  53. }
  54. }"#;
  55. pretty_assertions::assert_eq!(&out, &expected);
  56. }