Files
dioxus/packages/rsx/tests/hotreloads.rs
T
Jonathan Kelley eb79e61642 Add a ton of comments to rsx/hotreload, add snapshot testing, refactor a bit to simplify the crate (#2130)
Merge dynamic context and dynamic mapping, clean up the rsx hotreload logic, and add location data to the Rsx objects
2024-03-24 13:31:26 -07:00

50 lines
1.4 KiB
Rust

use dioxus_rsx::hot_reload::{diff_rsx, DiffResult};
use syn::File;
macro_rules! assert_rsx_changed {
(
$( #[doc = $doc:expr] )*
$name:ident
) => {
$( #[doc = $doc] )*
#[test]
fn $name() {
let old = include_str!(concat!("./valid/", stringify!($name), ".old.rsx"));
let new = include_str!(concat!("./valid/", stringify!($name), ".new.rsx"));
let (old, new) = load_files(old, new);
assert!(matches!( diff_rsx(&new, &old), DiffResult::RsxChanged { .. }));
}
};
}
macro_rules! assert_code_changed {
(
$( #[doc = $doc:expr] )*
$name:ident
) => {
$( #[doc = $doc] )*
#[test]
fn $name() {
let old = include_str!(concat!("./invalid/", stringify!($name), ".old.rsx"));
let new = include_str!(concat!("./invalid/", stringify!($name), ".new.rsx"));
let (old, new) = load_files(old, new);
assert!(matches!(diff_rsx(&new, &old), DiffResult::CodeChanged(_) ));
}
};
}
fn load_files(old: &str, new: &str) -> (File, File) {
let old = syn::parse_file(old).unwrap();
let new = syn::parse_file(new).unwrap();
(old, new)
}
assert_rsx_changed![combo];
assert_rsx_changed![expr];
assert_rsx_changed![for_];
assert_rsx_changed![if_];
assert_rsx_changed![let_];
assert_rsx_changed![nested];
assert_code_changed![changedexpr];