Skip to content

Commit 337ebbd

Browse files
authored
Merge pull request #936 from godot-rust/qol/float-formatting
Update hint_string tests to account for Godot 4.4 floats with `.0` formatting
2 parents 5e9b965 + f741e27 commit 337ebbd

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

godot-core/src/registry/property.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,15 @@ pub mod export_info_functions {
206206
hide_slider: bool,
207207
suffix: Option<String>,
208208
) -> PropertyHintInfo {
209+
// From Godot 4.4, GDScript uses `.0` for integral floats, see https://github.com/godotengine/godot/pull/47502.
210+
// We still register them the old way, to test compatibility. See also property_template_test.rs.
211+
209212
let hint_beginning = if let Some(step) = step {
210213
format!("{min},{max},{step}")
211214
} else {
212215
format!("{min},{max}")
213216
};
217+
214218
let rest = comma_separate_boolean_idents!(
215219
or_greater,
216220
or_less,

itest/rust/src/object_tests/property_template_test.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ fn property_template_test(ctx: &TestContext) {
5151

5252
assert!(!properties.is_empty());
5353

54-
for property in gdscript_properties.get_property_list().iter_shared() {
55-
let name = property.get("name").unwrap().to::<String>();
54+
for mut gdscript_prop in gdscript_properties.get_property_list().iter_shared() {
55+
let name = gdscript_prop.at("name").to::<String>();
5656

5757
let Some(mut rust_prop) = properties.remove(&name) else {
5858
continue;
5959
};
6060

61-
let mut rust_usage = rust_prop.get("usage").unwrap().to::<i64>();
61+
let mut rust_usage = rust_prop.at("usage").to::<i64>();
6262

6363
// the GDSscript variables are script variables, and so have `PROPERTY_USAGE_SCRIPT_VARIABLE` set.
6464
if rust_usage == PropertyUsageFlags::STORAGE.ord() as i64 {
@@ -71,9 +71,26 @@ fn property_template_test(ctx: &TestContext) {
7171

7272
rust_prop.set("usage", rust_usage);
7373

74-
if rust_prop != property {
74+
// From Godot 4.4, GDScript uses `.0` for integral floats, see https://github.com/godotengine/godot/pull/47502.
75+
// We still register them the old way, to test compatibility. See also godot-core/src/registry/property.rs.
76+
// Since GDScript now registers them with `.0`, we need to account for that.
77+
if GdextBuild::since_api("4.4") {
78+
let mut hint_string = gdscript_prop.at("hint_string").to::<String>();
79+
80+
// Don't check against `.0` to not accidentally catch `.02`. We don't have regex available here.
81+
if hint_string.contains(".0,") {
82+
hint_string = hint_string.replace(".0,", ",");
83+
gdscript_prop.set("hint_string", hint_string.clone());
84+
}
85+
86+
if hint_string.ends_with(".0") {
87+
gdscript_prop.set("hint_string", hint_string.trim_end_matches(".0"));
88+
}
89+
}
90+
91+
if rust_prop != gdscript_prop {
7592
errors.push(format!(
76-
"mismatch in property {name}:\n GDScript: {property:?}\n Rust: {rust_prop:?}"
93+
"mismatch in property {name}:\n GDScript: {gdscript_prop:?}\n Rust: {rust_prop:?}"
7794
));
7895
}
7996
}

0 commit comments

Comments
 (0)