Skip to content

Commit 797d485

Browse files
committed
Simplify arg passing in some tests
1 parent 0372818 commit 797d485

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

godot-core/src/tools/save_load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ where
164164
{
165165
// TODO unclone GString
166166
let res = ResourceSaver::singleton()
167-
.save_ex(obj.upcast())
167+
.save_ex(obj)
168168
.path(path.clone())
169169
.done();
170170

itest/rust/src/builtin_tests/containers/array_test.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ fn untyped_array_return_from_godot_func() {
394394
let mut node = Node::new_alloc();
395395
let mut child = Node::new_alloc();
396396
child.set_name("child_node".into());
397-
node.add_child(child.clone());
397+
node.add_child(&child);
398398
node.queue_free(); // Do not leak even if the test fails.
399399
let result = node.get_node_and_resource("child_node".into());
400400

@@ -431,7 +431,7 @@ fn typed_array_return_from_godot_func() {
431431
let mut node = Node::new_alloc();
432432
let mut child = Node::new_alloc();
433433
child.set_name("child_node".into());
434-
node.add_child(child.clone());
434+
node.add_child(&child);
435435
node.queue_free(); // Do not leak even if the test fails.
436436
let children = node.get_children();
437437

@@ -477,10 +477,7 @@ fn array_should_format_with_display() {
477477
#[cfg(since_api = "4.2")]
478478
fn array_sort_custom() {
479479
let mut a = array![1, 2, 3, 4];
480-
let func = Callable::from_fn("sort backwards", |args: &[&Variant]| {
481-
let res = i32::from_variant(args[0]) > i32::from_variant(args[1]);
482-
Ok(Variant::from(res))
483-
});
480+
let func = backwards_sort_callable();
484481
a.sort_unstable_custom(func);
485482
assert_eq!(a, array![4, 3, 2, 1]);
486483
}
@@ -489,14 +486,18 @@ fn array_sort_custom() {
489486
#[cfg(since_api = "4.2")]
490487
fn array_binary_search_custom() {
491488
let a = array![5, 4, 2, 1];
492-
let func = Callable::from_fn("sort backwards", |args: &[&Variant]| {
493-
let res = i32::from_variant(args[0]) > i32::from_variant(args[1]);
494-
Ok(Variant::from(res))
495-
});
489+
let func = backwards_sort_callable();
496490
assert_eq!(a.bsearch_custom(&1, func.clone()), 3);
497491
assert_eq!(a.bsearch_custom(&3, func), 2);
498492
}
499493

494+
fn backwards_sort_callable() -> Callable {
495+
Callable::from_fn("sort backwards", |args: &[&Variant]| {
496+
let res = args[0].to::<i32>() > args[1].to::<i32>();
497+
Ok(res.to_variant())
498+
})
499+
}
500+
500501
#[itest]
501502
fn array_shrink() {
502503
let mut a = array![1, 5, 4, 3, 8];

itest/rust/src/engine_tests/node_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ fn node_scene_tree() {
6767

6868
let mut parent = Node::new_alloc();
6969
parent.set_name("parent".into());
70-
parent.add_child(child.clone());
70+
parent.add_child(&child);
7171

7272
let mut scene = PackedScene::new_gd();
73-
let err = scene.pack(parent.clone());
73+
let err = scene.pack(&parent);
7474
assert_eq!(err, global::Error::OK);
7575

7676
let mut tree = SceneTree::new_alloc();

0 commit comments

Comments
 (0)