Skip to content

Commit 862ad96

Browse files
committed
add unit tests
1 parent 5d24069 commit 862ad96

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,11 +1475,14 @@ unsafe impl<S: SystemParamState, P: SystemParam + 'static> SystemParamState
14751475

14761476
#[cfg(test)]
14771477
mod tests {
1478+
use std::marker::PhantomData;
1479+
14781480
use super::SystemParam;
14791481
use crate::{
14801482
self as bevy_ecs, // Necessary for the `SystemParam` Derive when used inside `bevy_ecs`.
14811483
query::WorldQuery,
1482-
system::Query,
1484+
schedule::SystemLabel,
1485+
system::{ParamSet, Query},
14831486
};
14841487

14851488
// Compile test for #2838
@@ -1492,4 +1495,65 @@ mod tests {
14921495
> {
14931496
_query: Query<'w, 's, Q, F>,
14941497
}
1498+
1499+
//
1500+
// Test auto-labels with the `SystemParam` derive
1501+
1502+
#[derive(SystemLabel)]
1503+
struct LabelA;
1504+
#[derive(SystemLabel)]
1505+
struct LabelB;
1506+
1507+
#[derive(SystemParam, Default)]
1508+
#[system_param(label = LabelA)]
1509+
struct A<'w, 's> {
1510+
#[system_param(ignore)]
1511+
_marker: PhantomData<Query<'w, 's, ()>>,
1512+
}
1513+
#[derive(SystemParam)]
1514+
#[system_param(label = LabelB)]
1515+
struct B<'w, 's> {
1516+
#[system_param(ignore)]
1517+
_marker: PhantomData<Query<'w, 's, ()>>,
1518+
}
1519+
1520+
#[test]
1521+
fn test_auto_labels() {
1522+
let a_labels = A::auto_labels();
1523+
assert!(a_labels.contains(&LabelA.as_label()));
1524+
1525+
let b_labels = B::auto_labels();
1526+
assert!(b_labels.contains(&LabelB.as_label()));
1527+
}
1528+
1529+
#[derive(SystemParam)]
1530+
struct Ab<'w, 's> {
1531+
_a: A<'w, 's>,
1532+
_b: B<'w, 's>,
1533+
}
1534+
1535+
#[test]
1536+
fn test_auto_labels_derive() {
1537+
let ab_labels = Ab::auto_labels();
1538+
assert!(ab_labels.contains(&LabelA.as_label()));
1539+
assert!(ab_labels.contains(&LabelB.as_label()));
1540+
}
1541+
1542+
// Test auto-labels in paramsets
1543+
1544+
#[test]
1545+
fn test_auto_labels_paramset() {
1546+
let set_labels = ParamSet::<(A, B)>::auto_labels();
1547+
assert!(set_labels.contains(&LabelA.as_label()));
1548+
assert!(set_labels.contains(&LabelB.as_label()));
1549+
}
1550+
1551+
// Test auto-labels in tuples
1552+
1553+
#[test]
1554+
fn test_auto_labels_tuple() {
1555+
let tup_labels = <(A, B)>::auto_labels();
1556+
assert!(tup_labels.contains(&LabelA.as_label()));
1557+
assert!(tup_labels.contains(&LabelB.as_label()));
1558+
}
14951559
}

0 commit comments

Comments
 (0)