Skip to content

Commit 6d3421a

Browse files
committed
simple tests
1 parent 3edd573 commit 6d3421a

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

crates/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bevy = ["dep:bevy"]
1717
[dependencies]
1818
prost = "0.12"
1919
serde = { version = "1", features = ["derive"], optional = true }
20-
bevy = { version = "0.16.0-rc", default-features = false, optional = true }
20+
bevy = { version = "0.16.0-rc", default-features = false, optional = true, features = ["std"] }
2121
variadics_please = "1.1.0"
2222

2323
[dev-dependencies]

crates/core/src/yarn_fn/function_registry.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,32 @@ mod tests {
136136
assert_eq!(result, 1.0);
137137
}
138138

139+
#[cfg(feature = "bevy")]
140+
#[test]
141+
fn can_access_bevy_world() {
142+
let mut functions = YarnFnRegistry::default();
143+
let mut world = World::default();
144+
145+
let entity = world.spawn(Name::new("test_entity")).id();
146+
147+
functions.register_function(
148+
"test1",
149+
world.register_system(move |query: Query<(Entity, &Name)>| {
150+
let mut did_find = false;
151+
for (found_entity, found_name) in &query {
152+
assert_eq!(found_entity, entity);
153+
assert_eq!(found_name.as_str(), "test_entity");
154+
did_find = true;
155+
}
156+
did_find
157+
}),
158+
);
159+
160+
let function1 = functions.get("test1").unwrap();
161+
let result1: bool = function1.call(vec![], &mut world).try_into().unwrap();
162+
assert!(result1);
163+
}
164+
139165
#[test]
140166
fn can_add_multiple_fns() {
141167
let mut functions = YarnFnRegistry::default();

crates/core/src/yarn_fn/function_wrapping.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ mod bevy_functions {
190190

191191
macro_rules! impl_yarn_fn_tuple_bevy {
192192
($($yarn_param: ident),*) => {
193-
#[allow(non_snake_case)]
193+
#[allow(non_snake_case, unused_parens)]
194194
impl<'a, Output, $($yarn_param),*> YarnFn<(($($yarn_param,)*), Output)> for SystemId<In<($($yarn_param),*)>, Output>
195195
where
196196
$($yarn_param: TryFrom<YarnValue> + 'static,)*
@@ -199,6 +199,7 @@ mod bevy_functions {
199199
type Out = Output;
200200
#[allow(non_snake_case)]
201201
fn call(&self, input: Vec<YarnValue>, world: &mut World) -> Self::Out {
202+
#[allow(unused)]
202203
let mut input = VecDeque::from(input);
203204
$(
204205
assert!(!input.is_empty(), "Passed too few arguments to Function");
@@ -218,17 +219,17 @@ mod bevy_functions {
218219
impl<'a, Output> YarnFn<Output> for SystemId<(), Output>
219220
where
220221
Output: IntoYarnValueFromNonYarnValue + 'static,
221-
{
222-
type Out = Output;
223-
#[allow(non_snake_case)]
224-
fn call(&self, _input: Vec<YarnValue>, world: &mut World) -> Self::Out {
225-
world.run_system(*self).unwrap()
226-
}
222+
{
223+
type Out = Output;
224+
#[allow(non_snake_case)]
225+
fn call(&self, _input: Vec<YarnValue>, world: &mut World) -> Self::Out {
226+
world.run_system(*self).unwrap()
227+
}
227228

228-
fn parameter_types(&self) -> Vec<TypeId> {
229-
vec![]
230-
}
229+
fn parameter_types(&self) -> Vec<TypeId> {
230+
vec![]
231231
}
232+
}
232233
}
233234

234235
macro_rules! impl_yarn_fn_tuple {
@@ -373,22 +374,28 @@ mod tests {
373374
#[test]
374375
fn accepts_system() {
375376
let mut world = World::default();
376-
fn f(_: In<u32>, _: Query<Entity>) -> u32 { 0 }
377+
fn f(_: In<u32>, _: Query<Entity>) -> u32 {
378+
0
379+
}
377380
accept_yarn_fn(world.register_system(f));
378381
}
379382
#[cfg(feature = "bevy")]
380383
#[test]
381384
fn accepts_systemparam_only_system() {
382385
let mut world = World::default();
383-
fn f(_: Query<Entity>) -> u32 { 0 }
386+
fn f(_: Query<Entity>) -> u32 {
387+
0
388+
}
384389
accept_yarn_fn(world.register_system(f));
385390
}
386391

387392
#[cfg(feature = "bevy")]
388393
#[test]
389394
fn accepts_degenerate_system() {
390395
let mut world = World::default();
391-
fn f() -> u32 { 0 }
396+
fn f() -> u32 {
397+
0
398+
}
392399
accept_yarn_fn(world.register_system(f));
393400
}
394401

0 commit comments

Comments
 (0)