Add failing test for chaining

This commit is contained in:
JMS55 2024-11-20 22:17:19 -08:00
parent 7476d76da3
commit c952673e30

View file

@ -136,7 +136,7 @@ mod tests {
reactivity::{update_reactive_components, ReactiveComponentExpressions}, reactivity::{update_reactive_components, ReactiveComponentExpressions},
}; };
#[derive(Component)] #[derive(Component, PartialEq, Eq, Debug)]
struct Foo(u32); struct Foo(u32);
#[derive(Component, PartialEq, Eq, Debug)] #[derive(Component, PartialEq, Eq, Debug)]
@ -162,4 +162,32 @@ mod tests {
assert_eq!(world.entity(sink).get::<Bar>(), Some(&Bar(1))); assert_eq!(world.entity(sink).get::<Bar>(), Some(&Bar(1)));
} }
#[test]
fn test_reactive_component_chaining() {
let mut world = World::new();
world.init_resource::<ReactiveComponentExpressions>();
let a = world.spawn(Foo(0)).id();
let b = world
.spawn(ReactiveComponent::new(a, |foo: &Foo| Foo(foo.0 + 1)))
.id();
let c = world
.spawn(ReactiveComponent::new(b, |foo: &Foo| Foo(foo.0 + 1)))
.id();
world.flush();
assert_eq!(world.entity(a).get::<Foo>(), Some(&Foo(0)));
assert_eq!(world.entity(b).get::<Foo>(), Some(&Foo(1)));
assert_eq!(world.entity(c).get::<Foo>(), Some(&Foo(2)));
world.get_mut::<Foo>(a).unwrap().0 = 3;
update_reactive_components(&mut world);
assert_eq!(world.entity(a).get::<Foo>(), Some(&Foo(3)));
assert_eq!(world.entity(b).get::<Foo>(), Some(&Foo(4)));
assert_eq!(world.entity(c).get::<Foo>(), Some(&Foo(5)));
}
} }