1
0

simple.rs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 LargeThing="asd">hello world!</div>
  12. <ai-is-awesome>hello world!</ai-is-awesome>
  13. </div>
  14. "#
  15. .trim();
  16. let dom = Dom::parse(html).unwrap();
  17. let body = rsx_rosetta::rsx_from_html(&dom);
  18. let out = dioxus_autofmt::write_block_out(body).unwrap();
  19. let expected = r#"
  20. div {
  21. div { class: "asd", "hello world!" }
  22. div { id: "asd", "hello world!" }
  23. div { id: "asd", "hello world!" }
  24. div { r#for: "asd", "hello world!" }
  25. div { r#async: "asd", "hello world!" }
  26. div { large_thing: "asd", "hello world!" }
  27. ai_is_awesome { "hello world!" }
  28. }"#;
  29. pretty_assertions::assert_eq!(&out, &expected);
  30. }
  31. #[test]
  32. fn deeply_nested() {
  33. let html = r#"
  34. <div>
  35. <div class="asd">
  36. <div class="asd">
  37. <div class="asd">
  38. <div class="asd">
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. "#
  45. .trim();
  46. let dom = Dom::parse(html).unwrap();
  47. let body = rsx_rosetta::rsx_from_html(&dom);
  48. let out = dioxus_autofmt::write_block_out(body).unwrap();
  49. let expected = r#"
  50. div {
  51. div { class: "asd",
  52. div { class: "asd",
  53. div { class: "asd", div { class: "asd" } }
  54. }
  55. }
  56. }"#;
  57. pretty_assertions::assert_eq!(&out, &expected);
  58. }