Skip to content

Commit 64d059e

Browse files
committed
Reorganize file structure of itest cases
Changes: * Group tests by shared semantics, rather than having all on top level. * Remove 2 tests in `builtin.rs` (Vector2, VariantArray), already covered through unit-tests and other itests.
1 parent d9bd66f commit 64d059e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+174
-182
lines changed

itest/rust/src/builtin_test.rs

Lines changed: 0 additions & 61 deletions
This file was deleted.

itest/rust/src/callable_test.rs renamed to itest/rust/src/builtin_tests/containers/callable_test.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66

77
use godot::bind::{godot_api, GodotClass};
8-
use godot::builtin::{varray, Callable, ToVariant, Variant};
9-
use godot::engine::Object;
8+
use godot::builtin::inner::InnerCallable;
9+
use godot::builtin::{varray, Callable, GodotString, StringName, ToVariant, Variant};
10+
use godot::engine::{Node2D, Object};
1011
use godot::obj::{Gd, Share};
11-
use godot::prelude::GodotString;
1212

1313
use crate::framework::itest;
1414

@@ -105,3 +105,23 @@ fn callable_call_return() {
105105
// errors in godot but does not crash
106106
assert_eq!(callable.callv(varray!["string"]), Variant::nil());
107107
}
108+
109+
#[itest]
110+
fn callable_call_engine() {
111+
let obj = Node2D::new_alloc();
112+
let cb = Callable::from_object_method(obj.share(), "set_position");
113+
let inner: InnerCallable = cb.as_inner();
114+
115+
assert!(!inner.is_null());
116+
assert_eq!(inner.get_object_id(), obj.instance_id().to_i64());
117+
assert_eq!(inner.get_method(), StringName::from("set_position"));
118+
119+
// TODO once varargs is available
120+
// let pos = Vector2::new(5.0, 7.0);
121+
// inner.call(&[pos.to_variant()]);
122+
// assert_eq!(obj.get_position(), pos);
123+
//
124+
// inner.bindv(array);
125+
126+
obj.free();
127+
}

itest/rust/src/variant_test.rs renamed to itest/rust/src/builtin_tests/containers/variant_test.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
66

7-
use crate::framework::{expect_panic, itest};
7+
use std::cmp::Ordering;
8+
use std::fmt::Display;
9+
810
use godot::builtin::{
911
dict, varray, FromVariant, GodotString, NodePath, StringName, ToVariant, Variant, Vector2,
1012
Vector3,
1113
};
14+
use godot::builtin::{
15+
Basis, Dictionary, VariantArray, VariantConversionError, VariantOperator, VariantType,
16+
};
1217
use godot::engine::Node2D;
1318
use godot::obj::InstanceId;
14-
use godot::prelude::{Basis, Dictionary, VariantArray, VariantConversionError};
15-
use godot::sys::{GodotFfi, VariantOperator, VariantType};
16-
use std::cmp::Ordering;
17-
use std::fmt::{Debug, Display};
19+
use godot::sys::GodotFfi;
20+
21+
use crate::common::roundtrip;
22+
use crate::framework::{expect_panic, itest};
1823

1924
const TEST_BASIS: Basis = Basis::from_rows(
2025
Vector3::new(1.0, 2.0, 3.0),
@@ -408,19 +413,6 @@ fn variant_hash_correct() {
408413

409414
// ----------------------------------------------------------------------------------------------------------------------------------------------
410415

411-
pub(crate) fn roundtrip<T>(value: T)
412-
where
413-
T: FromVariant + ToVariant + PartialEq + Debug,
414-
{
415-
// TODO test other roundtrip (first FromVariant, then ToVariant)
416-
// Some values can be represented in Variant, but not in T (e.g. Variant(0i64) -> Option<InstanceId> -> Variant is lossy)
417-
418-
let variant = value.to_variant();
419-
let back = T::try_from_variant(&variant).unwrap();
420-
421-
assert_eq!(value, back);
422-
}
423-
424416
fn truncate_bad<T>(original_value: i64)
425417
where
426418
T: FromVariant + Display,

0 commit comments

Comments
 (0)