@@ -394,7 +394,7 @@ fn untyped_array_return_from_godot_func() {
394
394
let mut node = Node :: new_alloc ( ) ;
395
395
let mut child = Node :: new_alloc ( ) ;
396
396
child. set_name ( "child_node" . into ( ) ) ;
397
- node. add_child ( child. clone ( ) ) ;
397
+ node. add_child ( & child) ;
398
398
node. queue_free ( ) ; // Do not leak even if the test fails.
399
399
let result = node. get_node_and_resource ( "child_node" . into ( ) ) ;
400
400
@@ -431,7 +431,7 @@ fn typed_array_return_from_godot_func() {
431
431
let mut node = Node :: new_alloc ( ) ;
432
432
let mut child = Node :: new_alloc ( ) ;
433
433
child. set_name ( "child_node" . into ( ) ) ;
434
- node. add_child ( child. clone ( ) ) ;
434
+ node. add_child ( & child) ;
435
435
node. queue_free ( ) ; // Do not leak even if the test fails.
436
436
let children = node. get_children ( ) ;
437
437
@@ -477,10 +477,7 @@ fn array_should_format_with_display() {
477
477
#[ cfg( since_api = "4.2" ) ]
478
478
fn array_sort_custom ( ) {
479
479
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 ( ) ;
484
481
a. sort_unstable_custom ( func) ;
485
482
assert_eq ! ( a, array![ 4 , 3 , 2 , 1 ] ) ;
486
483
}
@@ -489,14 +486,18 @@ fn array_sort_custom() {
489
486
#[ cfg( since_api = "4.2" ) ]
490
487
fn array_binary_search_custom ( ) {
491
488
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 ( ) ;
496
490
assert_eq ! ( a. bsearch_custom( & 1 , func. clone( ) ) , 3 ) ;
497
491
assert_eq ! ( a. bsearch_custom( & 3 , func) , 2 ) ;
498
492
}
499
493
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
+
500
501
#[ itest]
501
502
fn array_shrink ( ) {
502
503
let mut a = array ! [ 1 , 5 , 4 , 3 , 8 ] ;
0 commit comments