Skip to content

Commit 6f85b4d

Browse files
authored
Merge pull request #1414 from godot-rust/qol/test-simplify-ord
Remove unnecessary `.ord()` calls for enums/bitfields
2 parents a8f4fa4 + 937686d commit 6f85b4d

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

itest/rust/src/builtin_tests/string/gstring_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ fn string_substr() {
145145
assert_eq!(string.substr(2..=4), "abl".into());
146146
}
147147

148-
// TODO(v0.5): enable after https://github.com/godotengine/godot/pull/113044 is merged.
149-
#[itest(skip)]
148+
#[itest]
150149
fn gstring_find() {
151150
let s = GString::from("Hello World");
152151

itest/rust/src/object_tests/property_template_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ fn property_template_test(ctx: &TestContext) {
5656
continue;
5757
};
5858

59-
let mut rust_usage = rust_prop.at("usage").to::<i64>();
59+
let mut rust_usage = rust_prop.at("usage").to::<PropertyUsageFlags>();
6060

6161
// The GDSscript variables are script variables, and so have `PROPERTY_USAGE_SCRIPT_VARIABLE` set.
6262
// Before 4.3, `PROPERTY_USAGE_SCRIPT_VARIABLE` did the same thing as `PROPERTY_USAGE_STORAGE` and
6363
// so GDScript didn't set both if it didn't need to.
6464
if GdextBuild::before_api("4.3") {
65-
if rust_usage == PropertyUsageFlags::STORAGE.ord() as i64 {
66-
rust_usage = PropertyUsageFlags::SCRIPT_VARIABLE.ord() as i64
65+
if rust_usage == PropertyUsageFlags::STORAGE {
66+
rust_usage = PropertyUsageFlags::SCRIPT_VARIABLE
6767
} else {
68-
rust_usage |= PropertyUsageFlags::SCRIPT_VARIABLE.ord() as i64;
68+
rust_usage |= PropertyUsageFlags::SCRIPT_VARIABLE;
6969
}
7070
} else {
71-
rust_usage |= PropertyUsageFlags::SCRIPT_VARIABLE.ord() as i64;
71+
rust_usage |= PropertyUsageFlags::SCRIPT_VARIABLE;
7272
}
7373

7474
rust_prop.set("usage", rust_usage);

itest/rust/src/object_tests/property_test.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use godot::builtin::{
1111
use godot::classes::{INode, IRefCounted, Node, Object, RefCounted, Resource, Texture};
1212
use godot::global::{PropertyHint, PropertyUsageFlags};
1313
use godot::meta::{GodotConvert, PropertyHintInfo, ToGodot};
14-
use godot::obj::{Base, EngineBitfield, EngineEnum, Gd, NewAlloc, NewGd, OnEditor};
14+
use godot::obj::{Base, Gd, NewAlloc, NewGd, OnEditor};
1515
use godot::register::property::{Export, Var};
1616
use godot::register::{godot_api, Export, GodotClass, GodotConvert, Var};
1717
use godot::test::itest;
@@ -454,10 +454,10 @@ fn derive_export() {
454454
.unwrap();
455455
// `class_name` should be empty for non-Object variants.
456456
check_property(&property, "class_name", "");
457-
check_property(&property, "type", VariantType::INT.ord());
458-
check_property(&property, "hint", PropertyHint::ENUM.ord());
457+
check_property(&property, "type", VariantType::INT);
458+
check_property(&property, "hint", PropertyHint::ENUM);
459459
check_property(&property, "hint_string", "A:0,B:1,C:2");
460-
check_property(&property, "usage", PropertyUsageFlags::DEFAULT.ord());
460+
check_property(&property, "usage", PropertyUsageFlags::DEFAULT);
461461
}
462462

463463
#[derive(GodotClass)]
@@ -489,13 +489,13 @@ fn export_resource() {
489489
.find(|c| c.get_or_nil("name") == "my_resource".to_variant())
490490
.unwrap();
491491
check_property(&property, "class_name", "CustomResource");
492-
check_property(&property, "type", VariantType::OBJECT.ord());
493-
check_property(&property, "hint", PropertyHint::RESOURCE_TYPE.ord());
492+
check_property(&property, "type", VariantType::OBJECT);
493+
check_property(&property, "hint", PropertyHint::RESOURCE_TYPE);
494494
check_property(&property, "hint_string", "CustomResource");
495495
check_property(
496496
&property,
497497
"usage",
498-
PropertyUsageFlags::DEFAULT.ord() | PropertyUsageFlags::EDITOR_INSTANTIATE_OBJECT.ord(),
498+
PropertyUsageFlags::DEFAULT | PropertyUsageFlags::EDITOR_INSTANTIATE_OBJECT,
499499
);
500500

501501
let property = class
@@ -504,10 +504,10 @@ fn export_resource() {
504504
.find(|c| c.get_or_nil("name") == "renamed_resource".to_variant())
505505
.unwrap();
506506
check_property(&property, "class_name", "NewNameCustomResource");
507-
check_property(&property, "type", VariantType::OBJECT.ord());
508-
check_property(&property, "hint", PropertyHint::RESOURCE_TYPE.ord());
507+
check_property(&property, "type", VariantType::OBJECT);
508+
check_property(&property, "hint", PropertyHint::RESOURCE_TYPE);
509509
check_property(&property, "hint_string", "NewNameCustomResource");
510-
check_property(&property, "usage", PropertyUsageFlags::DEFAULT.ord());
510+
check_property(&property, "usage", PropertyUsageFlags::DEFAULT);
511511

512512
class.free();
513513
}
@@ -551,9 +551,9 @@ fn override_export() {
551551
.find(|c| c.get_or_nil("name") == "resource".to_variant())
552552
.unwrap();
553553

554-
check_property(&property, "hint", PropertyHint::GLOBAL_FILE.ord());
554+
check_property(&property, "hint", PropertyHint::GLOBAL_FILE);
555555
check_property(&property, "hint_string", "SomethingRandom");
556-
check_property(&property, "usage", PropertyUsageFlags::GROUP.ord());
556+
check_property(&property, "usage", PropertyUsageFlags::GROUP);
557557
}
558558

559559
fn check_property(property: &Dictionary, key: &str, expected: impl ToGodot) {

0 commit comments

Comments
 (0)