Skip to content

Commit

Permalink
mutate observer unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejiaen committed Nov 1, 2024
1 parent 61511de commit 66db6df
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 63 deletions.
54 changes: 0 additions & 54 deletions crates/bevy_ecs/examples/mutate_obsover.rs

This file was deleted.

25 changes: 25 additions & 0 deletions crates/bevy_ecs/src/storage/entity_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,29 @@ impl EntityChange {
pub fn component(&self) -> ComponentId {
self.component
}
}

mod tests {
#![allow(unused_imports)]
use crate::component::ComponentId;
use crate::entity::Entity;
use crate::storage::{Changes, EntityChange};

#[test]
fn changes() {
let mut storage = Changes::new();
let entity = Entity::PLACEHOLDER;
let component = ComponentId::new(1);
storage.push(EntityChange::new(entity, component));
storage.push(EntityChange::new(entity, component));

let changes = storage.take_all();
assert_eq!(changes.len(), 2);
assert_eq!(storage.take_all().len(), 0);

changes.iter().for_each(|change| {
assert_eq!(change.component, component);
assert_eq!(change.entity, entity);
})
}
}
9 changes: 0 additions & 9 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ use bevy_ptr::UnsafeCellDeref;

use core::panic::Location;
use unsafe_world_cell::{UnsafeEntityCell, UnsafeWorldCell};
use crate::storage::Changes;

/// A [`World`] mutation.
///
Expand Down Expand Up @@ -136,14 +135,6 @@ pub struct World {
pub(crate) command_queue: RawCommandQueue,
}

impl World {

/// Just For Test
pub fn test(&mut self) -> &mut Changes {
&mut self.storages.changes
}
}

impl Default for World {
fn default() -> Self {
let mut world = Self {
Expand Down

0 comments on commit 66db6df

Please sign in to comment.