all native-core tests passing
This commit is contained in:
1 parent
ec3e02e4bb
commit
865c5aa957
11 files changed
+350
-324
No files matched your search
@@ -1,6 +1,8 @@
|
||||
use dioxus_native_core::node::NodeType;
|
||||
use dioxus_native_core::prelude::*;
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use shipyard::Component;
|
||||
|
||||
fn create_blank_element() -> NodeType {
|
||||
NodeType::Element(ElementNode {
|
||||
@@ -13,9 +15,10 @@ fn create_blank_element() -> NodeType {
|
||||
|
||||
#[test]
|
||||
fn node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct Number(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for Number {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -27,7 +30,7 @@ fn node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -38,7 +41,7 @@ fn node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -48,22 +51,29 @@ fn node_pass() {
|
||||
}
|
||||
|
||||
let mut tree: RealDom = RealDom::new(Box::new([Number::to_type_erased()]));
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
assert_eq!(tree.get(tree.root_id()).unwrap().get(), Some(&Number(1)));
|
||||
assert_eq!(
|
||||
tree.get(tree.root_id()).unwrap().get().as_deref(),
|
||||
Some(&Number(1))
|
||||
);
|
||||
|
||||
// mark the node as dirty
|
||||
tree.get_mut(tree.root_id()).unwrap().get_mut::<Number>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
assert_eq!(tree.get(tree.root_id()).unwrap().get(), Some(&Number(2)));
|
||||
tree.update_state(SendAnyMap::new());
|
||||
assert_eq!(
|
||||
tree.get(tree.root_id()).unwrap().get().as_deref(),
|
||||
Some(&Number(2))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dependant_node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = (SubtractNumber,);
|
||||
@@ -75,7 +85,7 @@ fn dependant_node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -86,7 +96,7 @@ fn dependant_node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -95,9 +105,10 @@ fn dependant_node_pass() {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct SubtractNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for SubtractNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -109,7 +120,7 @@ fn dependant_node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 -= 1;
|
||||
@@ -120,7 +131,7 @@ fn dependant_node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -133,36 +144,37 @@ fn dependant_node_pass() {
|
||||
AddNumber::to_type_erased(),
|
||||
SubtractNumber::to_type_erased(),
|
||||
]));
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-1)));
|
||||
|
||||
// mark the subtract state as dirty, it should update the add state
|
||||
tree.get_mut(tree.root_id())
|
||||
.unwrap()
|
||||
.get_mut::<SubtractNumber>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-2)));
|
||||
|
||||
// mark the add state as dirty, it should ~not~ update the subtract state
|
||||
tree.get_mut(tree.root_id()).unwrap().get_mut::<AddNumber>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(3)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(3)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn independant_node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -175,7 +187,7 @@ fn independant_node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -186,7 +198,7 @@ fn independant_node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -195,9 +207,10 @@ fn independant_node_pass() {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct SubtractNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for SubtractNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -210,7 +223,7 @@ fn independant_node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 -= 1;
|
||||
@@ -221,7 +234,7 @@ fn independant_node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -234,36 +247,36 @@ fn independant_node_pass() {
|
||||
AddNumber::to_type_erased(),
|
||||
SubtractNumber::to_type_erased(),
|
||||
]));
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-1)));
|
||||
|
||||
// mark the subtract state as dirty, it should ~not~ update the add state
|
||||
tree.get_mut(tree.root_id())
|
||||
.unwrap()
|
||||
.get_mut::<SubtractNumber>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-2)));
|
||||
|
||||
// mark the add state as dirty, it should ~not~ update the subtract state
|
||||
tree.get_mut(tree.root_id()).unwrap().get_mut::<AddNumber>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn down_pass() {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Component)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
impl Default for AddNumber {
|
||||
@@ -272,6 +285,7 @@ fn down_pass() {
|
||||
}
|
||||
}
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -284,7 +298,7 @@ fn down_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
if let Some((parent,)) = parent {
|
||||
@@ -297,7 +311,7 @@ fn down_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -321,25 +335,24 @@ fn down_pass() {
|
||||
parent.add_child(child1);
|
||||
parent.add_child(child2);
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
dbg!(root.id());
|
||||
assert_eq!(root.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(1)));
|
||||
|
||||
let child1 = tree.get(child1).unwrap();
|
||||
dbg!(child1.id());
|
||||
dbg!(child1.parent().unwrap().get::<AddNumber>());
|
||||
assert_eq!(child1.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(child1.get().as_deref(), Some(&AddNumber(2)));
|
||||
|
||||
let grandchild1 = tree.get(grandchild1).unwrap();
|
||||
assert_eq!(grandchild1.get(), Some(&AddNumber(3)));
|
||||
assert_eq!(grandchild1.get().as_deref(), Some(&AddNumber(3)));
|
||||
|
||||
let child2 = tree.get(child2).unwrap();
|
||||
assert_eq!(child2.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(child2.get().as_deref(), Some(&AddNumber(2)));
|
||||
|
||||
let grandchild2 = tree.get(grandchild2).unwrap();
|
||||
assert_eq!(grandchild2.get(), Some(&AddNumber(3)));
|
||||
assert_eq!(grandchild2.get().as_deref(), Some(&AddNumber(3)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -357,9 +370,10 @@ fn up_pass() {
|
||||
// 2=\
|
||||
// 1
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Component)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = (AddNumber,);
|
||||
type NodeDependencies = ();
|
||||
@@ -372,12 +386,10 @@ fn up_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
if let Some(children) = children {
|
||||
self.0 += children.iter().map(|(i,)| i.0).sum::<i32>();
|
||||
}
|
||||
self.0 += children.iter().map(|(i,)| i.0).sum::<i32>();
|
||||
true
|
||||
}
|
||||
|
||||
@@ -385,7 +397,7 @@ fn up_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self(1);
|
||||
@@ -409,20 +421,20 @@ fn up_pass() {
|
||||
parent.add_child(child1);
|
||||
parent.add_child(child2);
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(5)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(5)));
|
||||
|
||||
let child1 = tree.get(child1).unwrap();
|
||||
assert_eq!(child1.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(child1.get().as_deref(), Some(&AddNumber(2)));
|
||||
|
||||
let grandchild1 = tree.get(grandchild1).unwrap();
|
||||
assert_eq!(grandchild1.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(grandchild1.get().as_deref(), Some(&AddNumber(1)));
|
||||
|
||||
let child2 = tree.get(child2).unwrap();
|
||||
assert_eq!(child2.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(child2.get().as_deref(), Some(&AddNumber(2)));
|
||||
|
||||
let grandchild2 = tree.get(grandchild2).unwrap();
|
||||
assert_eq!(grandchild2.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(grandchild2.get().as_deref(), Some(&AddNumber(1)));
|
||||
}
|
||||
Reference in new issue
Block a user