From e8017d55757c2c2c364f5048431dffd4c2dfeebd Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Fri, 20 Oct 2023 09:45:40 +0200 Subject: [PATCH] Rename 2 OpenXR classes for readability --- godot-codegen/src/tests.rs | 5 +++++ godot-codegen/src/util.rs | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/godot-codegen/src/tests.rs b/godot-codegen/src/tests.rs index 366d21c21..dddb03ed0 100644 --- a/godot-codegen/src/tests.rs +++ b/godot-codegen/src/tests.rs @@ -31,6 +31,9 @@ fn test_pascal_conversion() { ("JSONRPC", "JsonRpc"), ("NetworkedMultiplayerENet", "NetworkedMultiplayerENet"), ("ObjectID", "ObjectId"), + ("OpenXRAPIExtension", "OpenXrApiExtension"), + ("ObjectID", "ObjectId"), + ("OpenXRIPBinding", "OpenXrIpBinding"), ("PackedFloat32Array", "PackedFloat32Array"), ("PCKPacker", "PckPacker"), ("PHashTranslation", "PHashTranslation"), @@ -77,6 +80,8 @@ fn test_snake_conversion() { ("JSONRPC", "json_rpc"), ("NetworkedMultiplayerENet", "networked_multiplayer_e_net"), ("ObjectID", "object_id"), + ("OpenXRAPIExtension", "open_xr_api_extension"), + ("OpenXRIPBinding", "open_xr_ip_binding"), ("PackedFloat32Array", "packed_float32_array"), ("PCKPacker", "pck_packer"), ("PHashTranslation", "p_hash_translation"), diff --git a/godot-codegen/src/util.rs b/godot-codegen/src/util.rs index 6571fedf5..bf1197951 100644 --- a/godot-codegen/src/util.rs +++ b/godot-codegen/src/util.rs @@ -13,6 +13,7 @@ use crate::{Context, GodotTy, ModName, RustTy, TyName}; use proc_macro2::{Ident, Literal, TokenStream}; use quote::{format_ident, quote, ToTokens}; +use heck::ToPascalCase; use std::fmt; #[derive(Clone, Debug, PartialEq, Eq)] @@ -431,9 +432,10 @@ pub fn to_snake_case(class_name: &str) -> String { use heck::ToSnakeCase; // Special cases - #[allow(clippy::single_match)] match class_name { "JSONRPC" => return "json_rpc".to_string(), + "OpenXRAPIExtension" => return "open_xr_api_extension".to_string(), + "OpenXRIPBinding" => return "open_xr_ip_binding".to_string(), _ => {} } @@ -448,10 +450,11 @@ pub fn to_snake_case(class_name: &str) -> String { pub fn to_pascal_case(class_name: &str) -> String { use heck::ToPascalCase; - // Special cases - #[allow(clippy::single_match)] + // Special cases: reuse snake_case impl to ensure at least consistency between those 2. match class_name { - "JSONRPC" => return "JsonRpc".to_string(), + "JSONRPC" | "OpenXRAPIExtension" | "OpenXRIPBinding" => { + return to_snake_case(class_name).to_pascal_case() + } _ => {} }