@@ -12,7 +12,7 @@ use godot::classes::mesh::PrimitiveType;
12
12
use godot:: classes:: window:: LayoutDirection ;
13
13
use godot:: classes:: { time, ArrayMesh } ;
14
14
use godot:: global:: { Key , Orientation } ;
15
- use godot:: obj:: NewGd ;
15
+ use godot:: obj:: { EngineEnum , NewGd } ;
16
16
use std:: collections:: HashSet ;
17
17
18
18
#[ itest]
@@ -92,6 +92,29 @@ fn enum_as_str() {
92
92
93
93
#[ itest]
94
94
fn enum_godot_name ( ) {
95
+ use godot:: obj:: EngineEnum ;
96
+ assert_eq ! (
97
+ godot_name( Orientation :: VERTICAL ) ,
98
+ Orientation :: VERTICAL . as_str( )
99
+ ) ;
100
+ assert_eq ! (
101
+ godot_name( Orientation :: HORIZONTAL ) ,
102
+ Orientation :: HORIZONTAL . as_str( )
103
+ ) ;
104
+
105
+ assert_eq ! ( godot_name( Key :: NONE ) , "KEY_NONE" ) ;
106
+ assert_eq ! ( godot_name( Key :: SPECIAL ) , "KEY_SPECIAL" ) ;
107
+ assert_eq ! ( godot_name( Key :: ESCAPE ) , "KEY_ESCAPE" ) ;
108
+ assert_eq ! ( godot_name( Key :: TAB ) , "KEY_TAB" ) ;
109
+ assert_eq ! ( godot_name( Key :: A ) , "KEY_A" ) ;
110
+
111
+ // Unknown enumerators (might come from the future).
112
+ assert_eq ! ( godot_name( Key :: from_ord( 1234 ) ) , "" ) ;
113
+ }
114
+
115
+ #[ itest]
116
+ #[ expect( deprecated) ]
117
+ fn enum_godot_name_deprecated ( ) {
95
118
use godot:: obj:: EngineEnum ;
96
119
assert_eq ! (
97
120
Orientation :: VERTICAL . godot_name( ) ,
@@ -107,4 +130,15 @@ fn enum_godot_name() {
107
130
assert_eq ! ( Key :: ESCAPE . godot_name( ) , "KEY_ESCAPE" ) ;
108
131
assert_eq ! ( Key :: TAB . godot_name( ) , "KEY_TAB" ) ;
109
132
assert_eq ! ( Key :: A . godot_name( ) , "KEY_A" ) ;
133
+
134
+ // Unknown enumerators (might come from the future).
135
+ assert_eq ! ( Key :: from_ord( 1234 ) . godot_name( ) , "" ) ;
136
+ }
137
+
138
+ fn godot_name < T : EngineEnum + Eq + PartialEq + ' static > ( value : T ) -> & ' static str {
139
+ T :: all_constants ( )
140
+ . iter ( )
141
+ . find ( |c| c. value ( ) == value)
142
+ . map ( |c| c. godot_name ( ) )
143
+ . unwrap_or ( "" ) // Previous behavior.
110
144
}
0 commit comments