1
0

simple.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 = 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 = 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", div { class: "asd" } }
  50. }
  51. }
  52. }"#;
  53. pretty_assertions::assert_eq!(&out, &expected);
  54. }