everyting but promises
This commit is contained in:
parent
763550b63a
commit
ca508bef58
5 changed files with 27 additions and 45 deletions
5
assets/tests/ruby/promise_runtime_error.rb
Normal file
5
assets/tests/ruby/promise_runtime_error.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def test_func
|
||||
rust_func.and_then do |x|
|
||||
print("abc" + 5)
|
||||
end
|
||||
end
|
||||
|
|
@ -3,7 +3,7 @@ $state = {
|
|||
}
|
||||
|
||||
def test_func
|
||||
# rust_func.and_then do |x|
|
||||
# $state['x'] = x
|
||||
# end
|
||||
rust_func.and_then do |x|
|
||||
$state['x'] = x
|
||||
end
|
||||
end
|
||||
|
|
|
|||
3
assets/tests/ruby/side_effects.rb
Normal file
3
assets/tests/ruby/side_effects.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def test_func
|
||||
spawn_entity
|
||||
end
|
||||
|
|
@ -331,11 +331,13 @@ impl<T: IntoValue> FuncArgs<'_, RubyValue, RubyRuntime> for Vec<T> {
|
|||
|
||||
macro_rules! impl_tuple {
|
||||
($($idx:tt $t:tt),+) => {
|
||||
impl<'a, $($t,)+> FuncArgs<'a, RubyValue, RubyRuntime>
|
||||
impl<'a, $($t: IntoValue,)+> FuncArgs<'a, RubyValue, RubyRuntime>
|
||||
for ($($t,)+)
|
||||
{
|
||||
fn parse(self, _engine: &'a magnus::Ruby) -> Vec<RubyValue> {
|
||||
todo!();
|
||||
vec![
|
||||
$(RubyValue::new(self.$idx.into_value()), )+
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ macro_rules! scripting_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_function_gets_called_from_rust_with_heterogenous_params() {
|
||||
fn test_script_function_gets_called_from_rust_with_multiple_params() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|_| {});
|
||||
|
|
@ -225,33 +225,7 @@ macro_rules! scripting_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_function_gets_called_from_rust_with_multiple_params() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|_| {});
|
||||
|
||||
let entity_id = run_script::<$runtime, _, _>(
|
||||
&mut app,
|
||||
format!(
|
||||
"tests/{}/script_function_gets_called_from_rust_with_multiple_params.{}",
|
||||
$script, $extension
|
||||
)
|
||||
.to_string(),
|
||||
|mut scripted_entities: Query<(Entity, &mut <$runtime as Runtime>::ScriptData)>,
|
||||
scripting_runtime: ResMut<$runtime>| {
|
||||
let (entity, mut script_data) = scripted_entities.single_mut().unwrap();
|
||||
scripting_runtime
|
||||
.call_fn("test_func", &mut script_data, entity, vec![1, 2])
|
||||
.unwrap();
|
||||
},
|
||||
);
|
||||
|
||||
<$runtime>::assert_state_key_value_i32(&app.world(), entity_id, "a_value", 1i32);
|
||||
<$runtime>::assert_state_key_value_i32(&app.world(), entity_id, "b_value", 2i32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_script_function_that_casues_runtime_error() {
|
||||
fn call_script_function_that_casues_runtime_error() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|_| {});
|
||||
|
|
@ -274,18 +248,14 @@ macro_rules! scripting_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_script_function_that_causes_runtime_error() {
|
||||
fn call_script_function_that_does_not_exist() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|_| {});
|
||||
|
||||
run_script::<$runtime, _, _>(
|
||||
&mut app,
|
||||
format!(
|
||||
"tests/{}/call_script_function_that_causes_runtime_error.{}",
|
||||
$script, $extension
|
||||
)
|
||||
.to_string(),
|
||||
format!("tests/{}/side_effects.{}", $script, $extension).to_string(),
|
||||
|mut scripted_entities: Query<(Entity, &mut <$runtime as Runtime>::ScriptData)>,
|
||||
scripting_runtime: ResMut<$runtime>| {
|
||||
let (entity, mut script_data) = scripted_entities.single_mut().unwrap();
|
||||
|
|
@ -297,7 +267,7 @@ macro_rules! scripting_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_script_function_gets_called_from_rust() {
|
||||
fn script_function_gets_called_from_rust() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|_| {});
|
||||
|
|
@ -316,7 +286,7 @@ macro_rules! scripting_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_return_via_promise() {
|
||||
fn return_via_promise() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|runtime| {
|
||||
|
|
@ -333,7 +303,7 @@ macro_rules! scripting_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_promise_runtime_error_does_not_panic() {
|
||||
fn promise_runtime_error() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|runtime| {
|
||||
|
|
@ -348,7 +318,7 @@ macro_rules! scripting_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_side_effects() {
|
||||
fn side_effects() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
@ -374,7 +344,7 @@ macro_rules! scripting_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_rust_function_gets_called_from_script() {
|
||||
fn rust_function_gets_called_from_script() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
#[derive(Default, Resource)]
|
||||
|
|
@ -519,7 +489,9 @@ mod ruby_tests {
|
|||
value: &str,
|
||||
) {
|
||||
let runtime = world.get_resource::<RubyRuntime>().unwrap();
|
||||
runtime.with_engine(|engine| {
|
||||
let key = key.to_string();
|
||||
let value = value.to_string();
|
||||
runtime.with_engine_thread(move |engine| {
|
||||
let state: magnus::value::Value = engine.eval("$state").unwrap();
|
||||
let res: String = state.funcall_public("[]", (key,)).unwrap();
|
||||
assert_eq!(res, value);
|
||||
|
|
|
|||
Loading…
Reference in a new issue