Skip to content

Commit de59637

Browse files
committed
update other tests
1 parent bf34256 commit de59637

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

crates/bevy_ecs/src/schedule/condition.rs

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ pub trait SystemCondition<Marker, In: SystemInput = ()>:
193193
CombinatorSystem::new(a, b, DebugName::owned(name))
194194
}
195195

196+
/// Returns a new run condition that only returns `true`
197+
/// if both this one and the passed `then_run` return `true`.
196198
#[deprecated = "use `.and_then(...)` instead, or `.and_eager(...)` to evaluate the conditions eagerly"]
197199
fn and<M, C: SystemCondition<M, In>>(self, then_run: C) -> AndThen<Self::System, C::System> {
198200
let a = IntoSystem::into_system(self);
@@ -330,6 +332,8 @@ pub trait SystemCondition<Marker, In: SystemInput = ()>:
330332
CombinatorSystem::new(a, b, DebugName::owned(name))
331333
}
332334

335+
/// Returns a new run condition that only returns `false`
336+
/// if both this one and the passed `then_run` return `true`.
333337
#[deprecated = "use `.nand_then(...) instead, or `.nand_eager(...)` to evaluate the conditions eagerly"]
334338
fn nand<M, C: SystemCondition<M, In>>(self, nand: C) -> NandThen<Self::System, C::System> {
335339
self.nand_then(nand)
@@ -417,6 +421,8 @@ pub trait SystemCondition<Marker, In: SystemInput = ()>:
417421
CombinatorSystem::new(a, b, DebugName::owned(name))
418422
}
419423

424+
/// Returns a new run condition that only returns `true`
425+
/// if both this one and the passed `else_run` return `false`.
420426
#[deprecated = "use `.nor_else(...)` instead, or `.nor_eager(...)` to evaluate the conditions eagerly"]
421427
fn nor<M, C: SystemCondition<M, In>>(self, else_run: C) -> NorElse<Self::System, C::System> {
422428
self.nor_else(else_run)
@@ -493,6 +499,8 @@ pub trait SystemCondition<Marker, In: SystemInput = ()>:
493499
CombinatorSystem::new(a, b, DebugName::owned(name))
494500
}
495501

502+
/// Returns a new run condition that returns `true`
503+
/// if either this one or the passed `or` return `true`.
496504
#[deprecated = "use `.or_else(...)` instead, or `.or_eager(...)` to eagerly evaluate both conditions"]
497505
fn or<M, C: SystemCondition<M, In>>(self, else_run: C) -> OrElse<Self::System, C::System> {
498506
self.or_else(else_run)
@@ -1714,7 +1722,7 @@ mod tests {
17141722
// ensure there are no `Vacant` entities
17151723
assert!(world.query::<&Vacant>().iter(&world).next().is_none());
17161724
assert!(matches!(
1717-
world.run_system_once((|| true).or(vacant)),
1725+
world.run_system_once((|| true).or_else(vacant)),
17181726
Ok(true)
17191727
));
17201728

@@ -1756,10 +1764,10 @@ mod tests {
17561764
);
17571765
}
17581766

1759-
assert_system(&mut world, is_true_inc.or(vacant), |c| {
1767+
assert_system(&mut world, is_true_inc.or_else(vacant), |c| {
17601768
test_true(c) || false
17611769
});
1762-
assert_system(&mut world, is_true_inc.nor(vacant), |c| {
1770+
assert_system(&mut world, is_true_inc.nor_else(vacant), |c| {
17631771
!(test_true(c) || false)
17641772
});
17651773
assert_system(&mut world, is_true_inc.xor(vacant), |c| {
@@ -1768,20 +1776,20 @@ mod tests {
17681776
assert_system(&mut world, is_true_inc.xnor(vacant), |c| {
17691777
!(test_true(c) ^ false)
17701778
});
1771-
assert_system(&mut world, is_true_inc.and(vacant), |c| {
1779+
assert_system(&mut world, is_true_inc.and_then(vacant), |c| {
17721780
test_true(c) && false
17731781
});
1774-
assert_system(&mut world, is_true_inc.nand(vacant), |c| {
1782+
assert_system(&mut world, is_true_inc.nand_then(vacant), |c| {
17751783
!(test_true(c) && false)
17761784
});
17771785

17781786
// even if `vacant` fails as the first condition, where applicable (or,
17791787
// xor), `is_true_inc` should still be called. `and` and `nand` short
17801788
// circuit on an initial `false`.
1781-
assert_system(&mut world, vacant.or(is_true_inc), |c| {
1789+
assert_system(&mut world, vacant.or_else(is_true_inc), |c| {
17821790
false || test_true(c)
17831791
});
1784-
assert_system(&mut world, vacant.nor(is_true_inc), |c| {
1792+
assert_system(&mut world, vacant.nor_else(is_true_inc), |c| {
17851793
!(false || test_true(c))
17861794
});
17871795
assert_system(&mut world, vacant.xor(is_true_inc), |c| {
@@ -1790,18 +1798,18 @@ mod tests {
17901798
assert_system(&mut world, vacant.xnor(is_true_inc), |c| {
17911799
!(false ^ test_true(c))
17921800
});
1793-
assert_system(&mut world, vacant.and(is_true_inc), |c| {
1801+
assert_system(&mut world, vacant.and_then(is_true_inc), |c| {
17941802
false && test_true(c)
17951803
});
1796-
assert_system(&mut world, vacant.nand(is_true_inc), |c| {
1804+
assert_system(&mut world, vacant.nand_then(is_true_inc), |c| {
17971805
!(false && test_true(c))
17981806
});
17991807

18001808
// the same logic ought to be the case with a condition that runs, but yields `false`:
1801-
assert_system(&mut world, is_true_inc.or(is_false_inc), |c| {
1809+
assert_system(&mut world, is_true_inc.or_else(is_false_inc), |c| {
18021810
test_true(c) || test_false(c)
18031811
});
1804-
assert_system(&mut world, is_true_inc.nor(is_false_inc), |c| {
1812+
assert_system(&mut world, is_true_inc.nor_else(is_false_inc), |c| {
18051813
!(test_true(c) || test_false(c))
18061814
});
18071815
assert_system(&mut world, is_true_inc.xor(is_false_inc), |c| {
@@ -1810,18 +1818,18 @@ mod tests {
18101818
assert_system(&mut world, is_true_inc.xnor(is_false_inc), |c| {
18111819
!(test_true(c) ^ test_false(c))
18121820
});
1813-
assert_system(&mut world, is_true_inc.and(is_false_inc), |c| {
1821+
assert_system(&mut world, is_true_inc.and_then(is_false_inc), |c| {
18141822
test_true(c) && test_false(c)
18151823
});
1816-
assert_system(&mut world, is_true_inc.nand(is_false_inc), |c| {
1824+
assert_system(&mut world, is_true_inc.nand_then(is_false_inc), |c| {
18171825
!(test_true(c) && test_false(c))
18181826
});
18191827

18201828
// and where one condition yields `false` and the other fails:
1821-
assert_system(&mut world, is_false_inc.or(vacant), |c| {
1829+
assert_system(&mut world, is_false_inc.or_else(vacant), |c| {
18221830
test_false(c) || false
18231831
});
1824-
assert_system(&mut world, is_false_inc.nor(vacant), |c| {
1832+
assert_system(&mut world, is_false_inc.nor_else(vacant), |c| {
18251833
!(test_false(c) || false)
18261834
});
18271835
assert_system(&mut world, is_false_inc.xor(vacant), |c| {
@@ -1830,18 +1838,18 @@ mod tests {
18301838
assert_system(&mut world, is_false_inc.xnor(vacant), |c| {
18311839
!(test_false(c) ^ false)
18321840
});
1833-
assert_system(&mut world, is_false_inc.and(vacant), |c| {
1841+
assert_system(&mut world, is_false_inc.and_then(vacant), |c| {
18341842
test_false(c) && false
18351843
});
1836-
assert_system(&mut world, is_false_inc.nand(vacant), |c| {
1844+
assert_system(&mut world, is_false_inc.nand_then(vacant), |c| {
18371845
!(test_false(c) && false)
18381846
});
18391847

18401848
// and where both conditions yield `true`:
1841-
assert_system(&mut world, is_true_inc.or(is_true_inc), |c| {
1849+
assert_system(&mut world, is_true_inc.or_else(is_true_inc), |c| {
18421850
test_true(c) || test_true(c)
18431851
});
1844-
assert_system(&mut world, is_true_inc.nor(is_true_inc), |c| {
1852+
assert_system(&mut world, is_true_inc.nor_else(is_true_inc), |c| {
18451853
!(test_true(c) || test_true(c))
18461854
});
18471855
assert_system(&mut world, is_true_inc.xor(is_true_inc), |c| {
@@ -1850,18 +1858,18 @@ mod tests {
18501858
assert_system(&mut world, is_true_inc.xnor(is_true_inc), |c| {
18511859
!(test_true(c) ^ test_true(c))
18521860
});
1853-
assert_system(&mut world, is_true_inc.and(is_true_inc), |c| {
1861+
assert_system(&mut world, is_true_inc.and_then(is_true_inc), |c| {
18541862
test_true(c) && test_true(c)
18551863
});
1856-
assert_system(&mut world, is_true_inc.nand(is_true_inc), |c| {
1864+
assert_system(&mut world, is_true_inc.nand_then(is_true_inc), |c| {
18571865
!(test_true(c) && test_true(c))
18581866
});
18591867

18601868
// and where both conditions yield `false`:
1861-
assert_system(&mut world, is_false_inc.or(is_false_inc), |c| {
1869+
assert_system(&mut world, is_false_inc.or_else(is_false_inc), |c| {
18621870
test_false(c) || test_false(c)
18631871
});
1864-
assert_system(&mut world, is_false_inc.nor(is_false_inc), |c| {
1872+
assert_system(&mut world, is_false_inc.nor_else(is_false_inc), |c| {
18651873
!(test_false(c) || test_false(c))
18661874
});
18671875
assert_system(&mut world, is_false_inc.xor(is_false_inc), |c| {
@@ -1870,10 +1878,10 @@ mod tests {
18701878
assert_system(&mut world, is_false_inc.xnor(is_false_inc), |c| {
18711879
!(test_false(c) ^ test_false(c))
18721880
});
1873-
assert_system(&mut world, is_false_inc.and(is_false_inc), |c| {
1881+
assert_system(&mut world, is_false_inc.and_then(is_false_inc), |c| {
18741882
test_false(c) && test_false(c)
18751883
});
1876-
assert_system(&mut world, is_false_inc.nand(is_false_inc), |c| {
1884+
assert_system(&mut world, is_false_inc.nand_then(is_false_inc), |c| {
18771885
!(test_false(c) && test_false(c))
18781886
});
18791887
}
@@ -1886,14 +1894,14 @@ mod tests {
18861894

18871895
schedule.add_systems(
18881896
(
1889-
increment_counter.run_if(every_other_time.and(|| true)), // Run every odd cycle.
1890-
increment_counter.run_if(every_other_time.nand(|| false)), // Always run.
1891-
double_counter.run_if(every_other_time.nor(|| false)), // Run every even cycle.
1892-
increment_counter.run_if(every_other_time.or(|| true)), // Always run.
1893-
increment_counter.run_if(every_other_time.xnor(|| true)), // Run every odd cycle.
1894-
double_counter.run_if(every_other_time.xnor(|| false)), // Run every even cycle.
1895-
increment_counter.run_if(every_other_time.xor(|| false)), // Run every odd cycle.
1896-
double_counter.run_if(every_other_time.xor(|| true)), // Run every even cycle.
1897+
increment_counter.run_if(every_other_time.and_then(|| true)), // Run every odd cycle.
1898+
increment_counter.run_if(every_other_time.nand_then(|| false)), // Always run.
1899+
double_counter.run_if(every_other_time.nor_else(|| false)), // Run every even cycle.
1900+
increment_counter.run_if(every_other_time.or_else(|| true)), // Always run.
1901+
increment_counter.run_if(every_other_time.xnor(|| true)), // Run every odd cycle.
1902+
double_counter.run_if(every_other_time.xnor(|| false)), // Run every even cycle.
1903+
increment_counter.run_if(every_other_time.xor(|| false)), // Run every odd cycle.
1904+
double_counter.run_if(every_other_time.xor(|| true)), // Run every even cycle.
18971905
)
18981906
.chain(),
18991907
);

crates/bevy_ecs/src/system/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ mod tests {
18761876
res.0 += 2;
18771877
},
18781878
)
1879-
.distributive_run_if(resource_exists::<A>.or(resource_exists::<B>)),
1879+
.distributive_run_if(resource_exists::<A>.or_else(resource_exists::<B>)),
18801880
);
18811881
sched.initialize(&mut world).unwrap();
18821882
sched.run(&mut world);

0 commit comments

Comments
 (0)