Skip to content

Commit

Permalink
Clean up some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Sep 18, 2024
1 parent a7b1023 commit 2a13c68
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 40 deletions.
2 changes: 1 addition & 1 deletion godot-core/src/global/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn instance_from_id(instance_id: i64) -> Option<Gd<crate::classes::Object>>
#[deprecated = "Instance utilities in `godot::global` will be removed. Use methods on `Gd` and `InstanceId` instead.\n\
For detailed reasons, see https://github.com/godot-rust/gdext/pull/892."]
pub fn is_instance_valid(instance: Variant) -> bool {
crate::gen::utilities::is_instance_valid(instance)
crate::gen::utilities::is_instance_valid(&instance)
}

#[deprecated = "Instance utilities in `godot::global` will be removed. Use methods on `Gd` and `InstanceId` instead.\n\
Expand Down
46 changes: 14 additions & 32 deletions itest/rust/src/builtin_tests/containers/variant_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ fn variant_get_type() {
let variant = gstr("hello").to_variant();
assert_eq!(variant.get_type(), VariantType::STRING);

let variant = sname("hello").to_variant();
assert_eq!(variant.get_type(), VariantType::STRING_NAME);

let variant = TEST_BASIS.to_variant();
assert_eq!(variant.get_type(), VariantType::BASIS)
}
Expand Down Expand Up @@ -263,14 +266,14 @@ fn variant_evaluate() {
evaluate(VariantOperator::MULTIPLY, 5, 2.5, 12.5);

evaluate(VariantOperator::EQUAL, gstr("hello"), gstr("hello"), true);
evaluate(VariantOperator::EQUAL, gstr("hello"), gname("hello"), true);
evaluate(VariantOperator::EQUAL, gname("rust"), gstr("rust"), true);
evaluate(VariantOperator::EQUAL, gname("rust"), gname("rust"), true);
evaluate(VariantOperator::EQUAL, gstr("hello"), sname("hello"), true);
evaluate(VariantOperator::EQUAL, sname("rust"), gstr("rust"), true);
evaluate(VariantOperator::EQUAL, sname("rust"), sname("rust"), true);

evaluate(VariantOperator::NOT_EQUAL, gstr("hello"), gstr("hallo"), true);
evaluate(VariantOperator::NOT_EQUAL, gstr("hello"), gname("hallo"), true);
evaluate(VariantOperator::NOT_EQUAL, gname("rust"), gstr("rest"), true);
evaluate(VariantOperator::NOT_EQUAL, gname("rust"), gname("rest"), true);
evaluate(VariantOperator::NOT_EQUAL, gstr("hello"), sname("hallo"), true);
evaluate(VariantOperator::NOT_EQUAL, sname("rust"), gstr("rest"), true);
evaluate(VariantOperator::NOT_EQUAL, sname("rust"), sname("rest"), true);

evaluate_fail(VariantOperator::EQUAL, 1, true);
evaluate_fail(VariantOperator::EQUAL, 0, false);
Expand Down Expand Up @@ -391,28 +394,7 @@ fn variant_null_object_is_nil() {
}

#[itest]
fn variant_type_correct() {
assert_eq!(Variant::nil().get_type(), VariantType::NIL);
assert_eq!(0.to_variant().get_type(), VariantType::INT);
assert_eq!(3.8.to_variant().get_type(), VariantType::FLOAT);
assert_eq!(false.to_variant().get_type(), VariantType::BOOL);
assert_eq!("string".to_variant().get_type(), VariantType::STRING);
assert_eq!(
StringName::from("string_name").to_variant().get_type(),
VariantType::STRING_NAME
);
assert_eq!(
VariantArray::default().to_variant().get_type(),
VariantType::ARRAY
);
assert_eq!(
Dictionary::default().to_variant().get_type(),
VariantType::DICTIONARY
);
}

#[itest]
fn variant_stringify_correct() {
fn variant_stringify() {
assert_eq!("value".to_variant().stringify(), gstr("value"));
assert_eq!(Variant::nil().stringify(), gstr("<null>"));
assert_eq!(true.to_variant().stringify(), gstr("true"));
Expand All @@ -428,10 +410,10 @@ fn variant_stringify_correct() {
}

#[itest]
fn variant_booleanize_correct() {
fn variant_booleanize() {
assert!(gstr("string").to_variant().booleanize());
assert!(10.to_variant().booleanize());
assert!(&varray![""].to_variant().booleanize());
assert!(varray![""].to_variant().booleanize());
assert!(dict! { "Key": 50 }.to_variant().booleanize());

assert!(!Dictionary::new().to_variant().booleanize());
Expand All @@ -442,7 +424,7 @@ fn variant_booleanize_correct() {
}

#[itest]
fn variant_hash_correct() {
fn variant_hash() {
let hash_is_not_0 = [
dict! {}.to_variant(),
gstr("").to_variant(),
Expand Down Expand Up @@ -583,6 +565,6 @@ fn gstr(s: &str) -> GString {
GString::from(s)
}

fn gname(s: &str) -> StringName {
fn sname(s: &str) -> StringName {
StringName::from(s)
}
4 changes: 2 additions & 2 deletions itest/rust/src/engine_tests/utilities_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ fn utilities_max() {
fn utilities_is_instance_valid() {
let node = Node3D::new_alloc();
let variant = Variant::from(node.clone());
assert!(is_instance_valid(&variant));
assert!(is_instance_valid(variant.clone()));

node.free();
assert!(!is_instance_valid(&variant));
assert!(!is_instance_valid(variant));
}
6 changes: 3 additions & 3 deletions itest/rust/src/object_tests/enum_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use godot::global::{Orientation, Key};
use std::collections::HashSet;

#[itest]
fn enum_ords_correct() {
fn enum_ords() {
use godot::obj::EngineEnum;
assert_eq!(CursorShape::CURSOR_ARROW.ord(), 0);
assert_eq!(CursorShape::CURSOR_IBEAM.ord(), 1);
Expand Down Expand Up @@ -73,7 +73,7 @@ fn add_surface_from_arrays() {
}

#[itest]
fn enum_as_str_correct() {
fn enum_as_str() {
use godot::obj::EngineEnum;
assert_eq!(Orientation::Vertical.as_str(), "VERTICAL");
assert_eq!(Orientation::Horizontal.as_str(), "HORIZONTAL");
Expand All @@ -86,7 +86,7 @@ fn enum_as_str_correct() {
}

#[itest]
fn enum_godot_name_correct() {
fn enum_godot_name() {
use godot::obj::EngineEnum;
assert_eq!(Orientation::Vertical.godot_name(), Orientation::Vertical.as_str());
assert_eq!(Orientation::Horizontal.godot_name(), Orientation::Vertical.as_str());
Expand Down
4 changes: 2 additions & 2 deletions itest/rust/src/object_tests/virtual_methods_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ fn test_get_called() {
}

#[itest]
fn test_get_returns_correct() {
fn test_get_returns() {
let mut obj = GetTest::new_gd();

{
Expand All @@ -636,7 +636,7 @@ fn test_set_called() {
}

#[itest]
fn test_set_sets_correct() {
fn test_set_sets() {
let mut obj = SetTest::new_gd();

assert_eq!(obj.bind().always_set_to_100, i64::default());
Expand Down

0 comments on commit 2a13c68

Please sign in to comment.