mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 05:03:47 +00:00
Add failing test for chaining
This commit is contained in:
parent
7476d76da3
commit
c952673e30
1 changed files with 29 additions and 1 deletions
|
@ -136,7 +136,7 @@ mod tests {
|
|||
reactivity::{update_reactive_components, ReactiveComponentExpressions},
|
||||
};
|
||||
|
||||
#[derive(Component)]
|
||||
#[derive(Component, PartialEq, Eq, Debug)]
|
||||
struct Foo(u32);
|
||||
|
||||
#[derive(Component, PartialEq, Eq, Debug)]
|
||||
|
@ -162,4 +162,32 @@ mod tests {
|
|||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue