Skip to content

Commit 8dbfd2b

Browse files
committed
convert more tests
1 parent f8456e6 commit 8dbfd2b

31 files changed

+129
-107
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local a = Vec3.new(2.0, -4.0, 6.0)
22

3-
assert(-a.x == -2.0, "Negation did not work")
4-
assert(-a.y == 4.0, "Negation did not work")
5-
assert(-a.z == -6.0, "Negation did not work")
3+
assert((-a).x == -2.0, "Negation did not work")
4+
assert((-a).y == 4.0, "Negation did not work")
5+
assert((-a).z == -6.0, "Negation did not work")

crates/languages/bevy_mod_scripting_rhai/src/bindings/reference.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ pub enum RhaiOperator {
204204
Unm,
205205
Pow,
206206
Eq,
207+
Ne,
207208
Lt,
208209
}
209210

@@ -219,6 +220,7 @@ impl RhaiOperator {
219220
RhaiOperator::Pow => "**",
220221
RhaiOperator::Eq => "==",
221222
RhaiOperator::Lt => "<",
223+
RhaiOperator::Ne => "!=",
222224
}
223225
}
224226
}
@@ -413,7 +415,7 @@ impl CustomType for RhaiReflectReference {
413415
let args = vec![ScriptValue::Reference(self_), other];
414416
let out = world.try_call_overloads(
415417
target_type_id,
416-
"mod",
418+
"rem",
417419
args,
418420
RHAI_CALLER_CONTEXT,
419421
)?;
@@ -426,7 +428,7 @@ impl CustomType for RhaiReflectReference {
426428
let target_type_id = self_.tail_type_id(world.clone())?.or_fake_id();
427429
let args = vec![ScriptValue::Reference(self_)];
428430
let out =
429-
world.try_call_overloads(target_type_id, "unm", args, RHAI_CALLER_CONTEXT)?;
431+
world.try_call_overloads(target_type_id, "neg", args, RHAI_CALLER_CONTEXT)?;
430432
out.into_dynamic()
431433
})
432434
.with_fn(
@@ -463,6 +465,26 @@ impl CustomType for RhaiReflectReference {
463465
out.into_dynamic()
464466
},
465467
)
468+
.with_fn(
469+
RhaiOperator::Ne.function_name(),
470+
|self_: Self, other: Dynamic| {
471+
let world = ThreadWorldContainer.try_get_world()?;
472+
let self_: ReflectReference = self_.0.clone();
473+
let other: ScriptValue = ScriptValue::from_dynamic(other)?;
474+
let target_type_id = self_.tail_type_id(world.clone())?.or_fake_id();
475+
let args = vec![ScriptValue::Reference(self_), other];
476+
let out = world.try_call_overloads(
477+
target_type_id,
478+
"eq",
479+
args,
480+
RHAI_CALLER_CONTEXT,
481+
)?;
482+
match out {
483+
ScriptValue::Bool(b) => ScriptValue::Bool(!b).into_dynamic(),
484+
_ => Err(InteropError::invariant("eq did not return a bool").into()),
485+
}
486+
},
487+
)
466488
.with_fn(
467489
RhaiOperator::Lt.function_name(),
468490
|self_: Self, other: Dynamic| {

crates/languages/bevy_mod_scripting_rhai/tests/data/api_availability/api_available_on_callback.lua

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn on_test() {
2+
assert!(type_of(world) != "()", "World was not found");
3+
assert!(type_of(world.get_type_by_name.call("TestComponent")) != "()", "Could not find TestComponent type");
4+
Entity.from_raw.call(1);
5+
}

crates/languages/bevy_mod_scripting_rhai/tests/data/api_availability/api_available_on_script_load.lua

Lines changed: 0 additions & 3 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assert!(type_of(world) != "()", "World was not found");
2+
assert!(type_of(world.get_type_by_name.call("TestComponent")) != "()", "Could not find TestComponent type");
3+
let out = Entity.from_raw.call(1);

crates/languages/bevy_mod_scripting_rhai/tests/data/clear/vec.lua

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let res_type = world.get_type_by_name.call("TestResourceWithVariousFields");
2+
let res = world.get_resource.call(res_type);
3+
4+
res.vec_usize.clear.call();
5+
6+
assert(res.vec_usize.len.call() == 0, "Clear did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/div/vec3.lua

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let a = Vec3.new_.call(2.0, 4.0, 6.0);
2+
let b = Vec3.new_.call(1.0, 2.0, 3.0);
3+
4+
assert((a / 2).x == 1.0, "Division did not work");
5+
assert((a / 2).y == 2.0, "Division did not work");
6+
assert((a / 2).z == 3.0, "Division did not work");
7+
8+
assert((a / b).x == 2.0, "Division did not work");
9+
assert((a / b).y == 2.0, "Division did not work");
10+
assert((a / b).z == 2.0, "Division did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/eq/vec3.lua

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let a = Vec3.new_.call(2.0, -4.0, 6.0);
2+
let b = Vec3.new_.call(4.0, 5.0, 6.0);
3+
4+
5+
assert((a == b) == false, "Equality did not work");
6+
assert((a != b) == true, "Inequality did not work");
7+
assert((a == a) == true, "Equality did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/get_type_by_name/registered_type_returns_correct_type.rhai

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let type = world.get_type_by_name.call("TestComponent");
22

3-
assert(type != (), "Registered type was not found");
3+
assert(type_of(type) != "()", "Registered type was not found");
44

55
let expected_type_name = "test_utils::test_data::TestComponent";
66
let expected_short_name = "TestComponent";

crates/languages/bevy_mod_scripting_rhai/tests/data/globals/dynamic_globals_are_in_scope.lua

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert(global_hello_world.call() == "hi!", "global_hello_world() == 'hi!'")

crates/languages/bevy_mod_scripting_rhai/tests/data/insert/vec.lua

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let res_type = world.get_type_by_name.call("TestResourceWithVariousFields");
2+
let res = world.get_resource.call(res_type);
3+
4+
res.vec_usize.insert.call(2, 42);
5+
6+
assert(res.vec_usize[2] == 42, "insert did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/iter/vec.lua

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let res_type = world.get_type_by_name.call("TestResourceWithVariousFields");
2+
let res = world.get_resource.call(res_type);
3+
4+
let iterated_vals = [];
5+
6+
for v in res.vec_usize {
7+
iterated_vals.push(v);
8+
}
9+
10+
assert(iterated_vals.len == 5, "Length is not 5");
11+
assert(iterated_vals[0] == 1, "First value is not 1");
12+
assert(iterated_vals[1] == 2, "Second value is not 2");
13+
assert(iterated_vals[2] == 3, "Third value is not 3");
14+
assert(iterated_vals[3] == 4, "Fourth value is not 4");
15+
assert(iterated_vals[4] == 5, "Fifth value is not 5");

crates/languages/bevy_mod_scripting_rhai/tests/data/mod/vec3.lua

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let a = Vec3.new_.call(2.0, 5.0, 6.0);
2+
let b = Vec3.new_.call(1.0, 2.0, 3.0);
3+
4+
assert((a % 2).x == 0.0, "Modulus did not work");
5+
assert((a % 2).y == 1.0, "Modulus did not work");
6+
assert((a % 2).z == 0.0, "Modulus did not work");
7+
8+
assert((a % b).x == 0.0, "Modulus did not work");
9+
assert((a % b).y == 1.0, "Modulus did not work");
10+
assert((a % b).z == 0.0, "Modulus did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/mul/vec3.lua

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let a = Vec3.new_.call(1.0, 2.0, 3.0);
2+
let b = Vec3.new_.call(4.0, 5.0, 6.0);
3+
4+
assert((a * 2).x == 2.0, "Multiplication did not work");
5+
assert((a * 2).y == 4.0, "Multiplication did not work");
6+
assert((a * 2).z == 6.0, "Multiplication did not work");
7+
8+
assert((a * b).x == 4.0, "Multiplication did not work");
9+
assert((a * b).y == 10.0, "Multiplication did not work");
10+
assert((a * b).z == 18.0, "Multiplication did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/pop/vec.lua

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let res_type = world.get_type_by_name.call("TestResourceWithVariousFields");
2+
let res = world.get_resource.call(res_type);
3+
4+
let popped = res.vec_usize.pop.call();
5+
6+
assert(popped == 5, "Pop did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/push/vec.lua

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let res_type = world.get_type_by_name.call("TestResourceWithVariousFields");
2+
let res = world.get_resource.call(res_type);
3+
4+
res.vec_usize.push.call(42);
5+
6+
assert(res.vec_usize[5] == 42, "Push did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/sub/vec3.lua

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let a = Vec3.new_.call(1.0, 2.0, 3.0);
2+
let b = Vec3.new_.call(4.0, 5.0, 6.0);
3+
4+
5+
assert((a - 1).x == 0.0, "Subtraction did not work");
6+
assert((a - 1).y == 1.0, "Subtraction did not work");
7+
assert((a - 1).z == 2.0, "Subtraction did not work");
8+
9+
assert((a - b).x == -3.0, "Subtraction did not work");
10+
assert((a - b).y == -3.0, "Subtraction did not work");
11+
assert((a - b).z == -3.0, "Subtraction did not work");

crates/languages/bevy_mod_scripting_rhai/tests/data/unm/vec3.lua

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let a = Vec3.new_.call(2.0, -4.0, 6.0);
2+
3+
assert((-a).x == -2.0, "Negation did not work");
4+
assert((-a).y == 4.0, "Negation did not work");
5+
assert((-a).z == -6.0, "Negation did not work");

0 commit comments

Comments
 (0)