#[macro_use] extern crate virtual_view; use virtual_view::diff_children; #[test] fn test_diff_children_complex() { let prev = [ view! {
}, view! {
}, view! {
}, ]; let next = [view! {
}, view! {
}]; let diff = diff_children(&prev, &next); assert!(diff.children[1].is_none()); } #[test] fn test_diff_children_keys() { let prev = [view! {
}, view! {
}]; let next = [view! {
}, view! {
}]; let diff = diff_children(&prev, &next); let &(index, ref key) = &diff.removes[0]; assert_eq!(index, 1); assert_eq!(key, &Some(&String::from("1"))); let &(ref key, index) = &diff.inserts[0]; assert_eq!(index, 0); assert_eq!(key, &Some(&String::from("1"))); } #[test] fn test_diff_children_insert() { let prev = [view! {
}]; let next = [view! {
}, view! {
}]; let diff = diff_children(&prev, &next); assert!(diff.children[0].is_some()); assert!(diff.children[1].is_some()); } #[test] fn test_diff_children_remove() { let prev = [view! {
}, view! {
}]; let next = [view! {
}]; let diff = diff_children(&prev, &next); assert!(diff.children[0].is_some()); assert!(diff.children[1].is_none()); }