finish migrating tests

This commit is contained in:
Evan Almloff 2023-02-02 14:48:02 -06:00
parent c8eb5c7dd7
commit 8dde4e492f
4 changed files with 107 additions and 126 deletions

View file

@ -338,8 +338,8 @@ fn creation() {
assert_eq!(tree.parent_id(child_id).unwrap(), parent_id);
assert_eq!(tree.children_ids(parent_id).unwrap(), &[child_id]);
assert_eq!(*tree.read::<i32>(parent_id).unwrap(), 1);
assert_eq!(*tree.read::<i32>(child_id).unwrap(), 0);
assert_eq!(*tree.get::<i32>(parent_id).unwrap(), 1);
assert_eq!(*tree.get::<i32>(child_id).unwrap(), 0);
}
#[test]
@ -371,10 +371,10 @@ fn insertion() {
assert_eq!(tree.parent_id(after).unwrap(), parent);
assert_eq!(tree.children_ids(parent).unwrap(), &[before, child, after]);
assert_eq!(*tree.read::<i32>(parent).unwrap(), 0);
assert_eq!(*tree.read::<i32>(before).unwrap(), 1);
assert_eq!(*tree.read::<i32>(child).unwrap(), 2);
assert_eq!(*tree.read::<i32>(after).unwrap(), 3);
assert_eq!(*tree.get::<i32>(parent).unwrap(), 0);
assert_eq!(*tree.get::<i32>(before).unwrap(), 1);
assert_eq!(*tree.get::<i32>(child).unwrap(), 2);
assert_eq!(*tree.get::<i32>(after).unwrap(), 3);
}
#[test]
@ -406,10 +406,10 @@ fn deletion() {
assert_eq!(tree.parent_id(after).unwrap(), parent);
assert_eq!(tree.children_ids(parent).unwrap(), &[before, child, after]);
assert_eq!(*tree.read::<i32>(parent).unwrap(), 0);
assert_eq!(*tree.read::<i32>(before).unwrap(), 1);
assert_eq!(*tree.read::<i32>(child).unwrap(), 2);
assert_eq!(*tree.read::<i32>(after).unwrap(), 3);
assert_eq!(*tree.get::<i32>(parent).unwrap(), 0);
assert_eq!(*tree.get::<i32>(before).unwrap(), 1);
assert_eq!(*tree.get::<i32>(child).unwrap(), 2);
assert_eq!(*tree.get::<i32>(after).unwrap(), 3);
tree.remove(child);
@ -422,10 +422,10 @@ fn deletion() {
assert_eq!(tree.parent_id(after).unwrap(), parent);
assert_eq!(tree.children_ids(parent).unwrap(), &[before, after]);
assert_eq!(*tree.read::<i32>(parent).unwrap(), 0);
assert_eq!(*tree.read::<i32>(before).unwrap(), 1);
assert_eq!(tree.read::<i32>(child), None);
assert_eq!(*tree.read::<i32>(after).unwrap(), 3);
assert_eq!(*tree.get::<i32>(parent).unwrap(), 0);
assert_eq!(*tree.get::<i32>(before).unwrap(), 1);
assert_eq!(tree.get::<i32>(child), None);
assert_eq!(*tree.get::<i32>(after).unwrap(), 3);
tree.remove(before);
@ -436,9 +436,9 @@ fn deletion() {
assert_eq!(tree.parent_id(after).unwrap(), parent);
assert_eq!(tree.children_ids(parent).unwrap(), &[after]);
assert_eq!(*tree.read::<i32>(parent).unwrap(), 0);
assert_eq!(tree.read::<i32>(before), None);
assert_eq!(*tree.read::<i32>(after).unwrap(), 3);
assert_eq!(*tree.get::<i32>(parent).unwrap(), 0);
assert_eq!(tree.get::<i32>(before), None);
assert_eq!(*tree.get::<i32>(after).unwrap(), 3);
tree.remove(after);
@ -447,8 +447,8 @@ fn deletion() {
assert_eq!(tree.height(parent), Some(0));
assert_eq!(tree.children_ids(parent).unwrap(), &[]);
assert_eq!(*tree.read::<i32>(parent).unwrap(), 0);
assert_eq!(tree.read::<i32>(after), None);
assert_eq!(*tree.get::<i32>(parent).unwrap(), 0);
assert_eq!(tree.get::<i32>(after), None);
}
#[derive(Debug)]
@ -704,80 +704,3 @@ fn remove() {
assert!(slab.read_slab::<i32>().get(node1_id).is_none());
assert_eq!(slab.len(), 1);
}
#[test]
fn get_many_mut_unchecked() {
let mut slab = AnySlab::new();
let mut parent = slab.insert();
parent.insert(0i32);
let parent = parent.id();
let mut child = slab.insert();
child.insert(1i32);
let child = child.id();
let mut grandchild = slab.insert();
grandchild.insert(2i32);
let grandchild = grandchild.id();
assert_eq!(slab.len(), 3);
println!("ids: {:#?}", [parent, child, grandchild]);
{
let i32_slab = slab.write_slab::<i32>();
let all =
unsafe { i32_slab.get_many_mut_unchecked([parent, child, grandchild].into_iter()) }
.unwrap();
assert_eq!(all, [&mut 0, &mut 1, &mut 2]);
}
{
let i32_slab = slab.write_slab::<i32>();
assert!(
unsafe { i32_slab.get_many_mut_unchecked([NodeId(3), NodeId(100)].into_iter()) }
.is_none()
)
}
}
#[test]
fn get_many_many_mut_unchecked() {
let mut slab = AnySlab::new();
let mut parent = slab.insert();
parent.insert(0i32);
parent.insert("0");
let parent = parent.id();
let mut child = slab.insert();
child.insert(1i32);
child.insert("1");
let child = child.id();
let mut grandchild = slab.insert();
grandchild.insert(2i32);
grandchild.insert("2");
let grandchild = grandchild.id();
println!("ids: {:#?}", [parent, child, grandchild]);
println!("slab: {:#?}", slab);
let num_entries = slab.write_slab::<i32>();
let all_num = unsafe {
num_entries
.as_any_mut()
.downcast_mut::<SlabStorage<i32>>()
.unwrap()
.get_many_mut_unchecked([parent, child, grandchild].into_iter())
}
.unwrap();
assert_eq!(all_num, [&mut 0, &mut 1, &mut 2]);
let str_entries = slab.write_slab::<&str>();
let all_str = unsafe {
str_entries
.as_any_mut()
.downcast_mut::<SlabStorage<&str>>()
.unwrap()
.get_many_mut_unchecked([parent, child, grandchild].into_iter())
}
.unwrap();
assert_eq!(all_str, [&mut "0", &mut "1", &mut "2"]);
}

View file

@ -266,68 +266,128 @@ fn traverse() {
let mut iter = PersistantElementIter::new();
let div_tag = "div".to_string();
assert!(matches!(
&rdom[iter.next(&rdom).id()].node_data.node_type,
&rdom
.get(iter.next(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Element(ElementNode { tag: div_tag, .. })
));
assert!(matches!(
&rdom[iter.next(&rdom).id()].node_data.node_type,
&rdom
.get(iter.next(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Element(ElementNode { tag: div_tag, .. })
));
let text1 = "hello".to_string();
assert!(matches!(
&rdom[iter.next(&rdom).id()].node_data.node_type,
&rdom
.get(iter.next(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Text(text1)
));
let p_tag = "p".to_string();
assert!(matches!(
&rdom[iter.next(&rdom).id()].node_data.node_type,
&rdom
.get(iter.next(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Element(ElementNode { tag: p_tag, .. })
));
let text2 = "world".to_string();
assert!(matches!(
&rdom[iter.next(&rdom).id()].node_data.node_type,
&rdom
.get(iter.next(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Text(text2)
));
let text3 = "hello world".to_string();
assert!(matches!(
&rdom[iter.next(&rdom).id()].node_data.node_type,
&rdom
.get(iter.next(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Text(text3)
));
assert!(matches!(
&rdom[iter.next(&rdom).id()].node_data.node_type,
&rdom
.get(iter.next(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Element(ElementNode { tag: div_tag, .. })
));
assert!(matches!(
&rdom[iter.prev(&rdom).id()].node_data.node_type,
&rdom
.get(iter.prev(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Text(text3)
));
assert!(matches!(
&rdom[iter.prev(&rdom).id()].node_data.node_type,
&rdom
.get(iter.prev(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Text(text2)
));
assert!(matches!(
&rdom[iter.prev(&rdom).id()].node_data.node_type,
&rdom
.get(iter.prev(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Element(ElementNode { tag: p_tag, .. })
));
assert!(matches!(
&rdom[iter.prev(&rdom).id()].node_data.node_type,
&rdom
.get(iter.prev(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Text(text1)
));
assert!(matches!(
&rdom[iter.prev(&rdom).id()].node_data.node_type,
&rdom
.get(iter.prev(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Element(ElementNode { tag: div_tag, .. })
));
assert!(matches!(
&rdom[iter.prev(&rdom).id()].node_data.node_type,
&rdom
.get(iter.prev(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Element(ElementNode { tag: div_tag, .. })
));
assert!(matches!(
&rdom[iter.prev(&rdom).id()].node_data.node_type,
&rdom
.get(iter.prev(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Element(ElementNode { tag: div_tag, .. })
));
assert!(matches!(
&rdom[iter.prev(&rdom).id()].node_data.node_type,
&rdom
.get(iter.prev(&rdom).id())
.unwrap()
.node_data()
.node_type,
NodeType::Text(text3)
));
}
@ -400,16 +460,16 @@ fn persist_removes() {
let root_tag = "Root".to_string();
let idx = iter1.next(&rdom).id();
dbg!(&rdom[idx].node_data.node_type);
dbg!(&rdom.get(idx).unwrap().node_data().node_type);
assert!(matches!(
&rdom[idx].node_data.node_type,
&rdom.get(idx).unwrap().node_data().node_type,
NodeType::Element(ElementNode { tag: root_tag, .. })
));
let idx = iter2.next(&rdom).id();
dbg!(&rdom[idx].node_data.node_type);
dbg!(&rdom.get(idx).unwrap().node_data().node_type);
assert!(matches!(
&rdom[idx].node_data.node_type,
&rdom.get(idx).unwrap().node_data().node_type,
NodeType::Element(ElementNode { tag: root_tag, .. })
));
}
@ -465,7 +525,7 @@ fn persist_instertions_before() {
let p_tag = "div".to_string();
let idx = iter.next(&rdom).id();
assert!(matches!(
&rdom[idx].node_data.node_type,
&rdom.get(idx).unwrap().node_data().node_type,
NodeType::Element(ElementNode { tag: p_tag, .. })
));
}
@ -520,13 +580,13 @@ fn persist_instertions_after() {
let p_tag = "p".to_string();
let idx = iter.next(&rdom).id();
assert!(matches!(
&rdom[idx].node_data.node_type,
&rdom.get(idx).unwrap().node_data().node_type,
NodeType::Element(ElementNode { tag: p_tag, .. })
));
let text = "hello world".to_string();
let idx = iter.next(&rdom).id();
assert!(matches!(
&rdom[idx].node_data.node_type,
&rdom.get(idx).unwrap().node_data().node_type,
NodeType::Text(text)
));
}

View file

@ -1,9 +1,9 @@
use dioxus::prelude::Props;
use dioxus_core::*;
use dioxus_native_core::{
node_ref::{AttributeMask, AttributeMaskBuilder, NodeMaskBuilder, NodeView},
node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView},
real_dom::RealDom,
Dependancy, NodeMask, Pass, SendAnyMap,
Dependancy, Pass, SendAnyMap,
};
use std::cell::Cell;
@ -308,7 +308,7 @@ impl Pass for BlablaState {
fn pass<'a>(
&mut self,
node_view: NodeView,
_: NodeView,
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,

View file

@ -1,11 +1,9 @@
use dioxus::prelude::*;
use dioxus_core::*;
use dioxus_native_core::{
node_ref::{AttributeMask, AttributeMaskBuilder, NodeMaskBuilder, NodeView},
node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView},
real_dom::RealDom,
Dependancy, NodeMask, Pass, SendAnyMap,
Dependancy, Pass, SendAnyMap,
};
use std::cell::Cell;
use std::sync::{Arc, Mutex};
use tokio::time::sleep;
@ -25,7 +23,7 @@ impl Pass for BlablaState {
fn pass<'a>(
&mut self,
node_view: NodeView,
_: NodeView,
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,