Skip to content

Commit

Permalink
Merge pull request #936 from godot-rust/qol/float-formatting
Browse files Browse the repository at this point in the history
Update hint_string tests to account for Godot 4.4 floats with `.0` formatting
  • Loading branch information
Bromeon authored Nov 3, 2024
2 parents 5e9b965 + f741e27 commit 337ebbd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions godot-core/src/registry/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,15 @@ pub mod export_info_functions {
hide_slider: bool,
suffix: Option<String>,
) -> PropertyHintInfo {
// From Godot 4.4, GDScript uses `.0` for integral floats, see https://github.com/godotengine/godot/pull/47502.
// We still register them the old way, to test compatibility. See also property_template_test.rs.

let hint_beginning = if let Some(step) = step {
format!("{min},{max},{step}")
} else {
format!("{min},{max}")
};

let rest = comma_separate_boolean_idents!(
or_greater,
or_less,
Expand Down
27 changes: 22 additions & 5 deletions itest/rust/src/object_tests/property_template_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ fn property_template_test(ctx: &TestContext) {

assert!(!properties.is_empty());

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

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

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

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

rust_prop.set("usage", rust_usage);

if rust_prop != property {
// From Godot 4.4, GDScript uses `.0` for integral floats, see https://github.com/godotengine/godot/pull/47502.
// We still register them the old way, to test compatibility. See also godot-core/src/registry/property.rs.
// Since GDScript now registers them with `.0`, we need to account for that.
if GdextBuild::since_api("4.4") {
let mut hint_string = gdscript_prop.at("hint_string").to::<String>();

// Don't check against `.0` to not accidentally catch `.02`. We don't have regex available here.
if hint_string.contains(".0,") {
hint_string = hint_string.replace(".0,", ",");
gdscript_prop.set("hint_string", hint_string.clone());
}

if hint_string.ends_with(".0") {
gdscript_prop.set("hint_string", hint_string.trim_end_matches(".0"));
}
}

if rust_prop != gdscript_prop {
errors.push(format!(
"mismatch in property {name}:\n GDScript: {property:?}\n Rust: {rust_prop:?}"
"mismatch in property {name}:\n GDScript: {gdscript_prop:?}\n Rust: {rust_prop:?}"
));
}
}
Expand Down

0 comments on commit 337ebbd

Please sign in to comment.