Add insert_if_new test for sparse set. (#19387)

Fixes #19081.
Simply created a duplicate of the existing `insert_if_new` test, but
using sparse sets.

## Testing:
The test passes on main, but fails if #19059 is reverted.
This commit is contained in:
AlephCubed 2025-05-26 20:15:30 -07:00 committed by GitHub
parent 33b3c08515
commit 7d32dfec18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2237,6 +2237,28 @@ mod tests {
assert_eq!(entity.get(), Some(&V("one")));
}
#[derive(Component, Debug, Eq, PartialEq)]
#[component(storage = "SparseSet")]
pub struct SparseV(&'static str);
#[derive(Component, Debug, Eq, PartialEq)]
#[component(storage = "SparseSet")]
pub struct SparseA;
#[test]
fn sparse_set_insert_if_new() {
let mut world = World::new();
let id = world.spawn(SparseV("one")).id();
let mut entity = world.entity_mut(id);
entity.insert_if_new(SparseV("two"));
entity.insert_if_new((SparseA, SparseV("three")));
entity.flush();
// should still contain "one"
let entity = world.entity(id);
assert!(entity.contains::<SparseA>());
assert_eq!(entity.get(), Some(&SparseV("one")));
}
#[test]
fn sorted_remove() {
let mut a = vec![1, 2, 3, 4, 5, 6, 7];