srcless.rs 868 B

123456789101112131415161718192021222324252627282930313233
  1. use dioxus_rsx::CallBody;
  2. use syn::parse_quote;
  3. macro_rules! test_case {
  4. (
  5. $path:literal
  6. ) => {
  7. works(include!($path), include_str!($path))
  8. };
  9. }
  10. /// Ensure we can write RSX blocks without a source file
  11. ///
  12. /// Useful in code generation use cases where we still want formatted code.
  13. #[test]
  14. fn write_block_out() {
  15. test_case!("./srcless/basic_expr.rsx");
  16. test_case!("./srcless/asset.rsx");
  17. }
  18. fn works(parsed: CallBody, src: &str) {
  19. let block = dioxus_autofmt::write_block_out(&parsed).unwrap();
  20. let src = src
  21. .trim()
  22. .trim_start_matches("parse_quote! {")
  23. .trim_end_matches('}');
  24. // normalize line endings for windows tests to pass
  25. pretty_assertions::assert_eq!(
  26. block.trim().lines().collect::<Vec<_>>().join("\n"),
  27. src.trim().lines().collect::<Vec<_>>().join("\n")
  28. );
  29. }