hotreloads.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use dioxus_rsx::hot_reload::{diff_rsx, DiffResult};
  2. use syn::File;
  3. macro_rules! assert_rsx_changed {
  4. (
  5. $( #[doc = $doc:expr] )*
  6. $name:ident
  7. ) => {
  8. $( #[doc = $doc] )*
  9. #[test]
  10. fn $name() {
  11. let old = include_str!(concat!("./valid/", stringify!($name), ".old.rsx"));
  12. let new = include_str!(concat!("./valid/", stringify!($name), ".new.rsx"));
  13. let (old, new) = load_files(old, new);
  14. assert!(matches!( diff_rsx(&new, &old), DiffResult::RsxChanged { .. }));
  15. }
  16. };
  17. }
  18. macro_rules! assert_code_changed {
  19. (
  20. $( #[doc = $doc:expr] )*
  21. $name:ident
  22. ) => {
  23. $( #[doc = $doc] )*
  24. #[test]
  25. fn $name() {
  26. let old = include_str!(concat!("./invalid/", stringify!($name), ".old.rsx"));
  27. let new = include_str!(concat!("./invalid/", stringify!($name), ".new.rsx"));
  28. let (old, new) = load_files(old, new);
  29. assert!(matches!(diff_rsx(&new, &old), DiffResult::CodeChanged(_) ));
  30. }
  31. };
  32. }
  33. fn load_files(old: &str, new: &str) -> (File, File) {
  34. let old = syn::parse_file(old).unwrap();
  35. let new = syn::parse_file(new).unwrap();
  36. (old, new)
  37. }
  38. assert_rsx_changed![combo];
  39. assert_rsx_changed![expr];
  40. assert_rsx_changed![for_];
  41. assert_rsx_changed![if_];
  42. assert_rsx_changed![let_];
  43. assert_rsx_changed![nested];
  44. assert_code_changed![changedexpr];