parsing.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. use dioxus_rsx::{CallBody, DynamicContext};
  2. use syn::Item;
  3. #[test]
  4. fn rsx_writeout_snapshot() {
  5. let body = parse_from_str(include_str!("./parsing/multiexpr.rsx"));
  6. assert_eq!(body.roots.len(), 1);
  7. let root = &body.roots[0];
  8. let el = match root {
  9. dioxus_rsx::BodyNode::Element(el) => el,
  10. _ => panic!("Expected an element"),
  11. };
  12. assert_eq!(el.name, "circle");
  13. assert_eq!(el.attributes.len(), 5);
  14. let mut context = DynamicContext::default();
  15. let o = context.render_static_node(&body.roots[0]);
  16. // hi!!!!!
  17. // you're probably here because you changed something in how rsx! generates templates and need to update the snapshot
  18. // This is a snapshot test. Make sure the contents are checked before committing a new snapshot.
  19. let stability_tested = o.to_string();
  20. assert_eq!(
  21. stability_tested.trim(),
  22. include_str!("./parsing/multiexpr.expanded.rsx").trim()
  23. );
  24. }
  25. fn parse_from_str(contents: &str) -> CallBody {
  26. // Parse the file
  27. let file = syn::parse_file(contents).unwrap();
  28. // The first token should be the macro call
  29. let Item::Macro(call) = file.items.first().unwrap() else {
  30. panic!("Expected a macro call");
  31. };
  32. call.mac.parse_body().unwrap()
  33. }