@@ -2,6 +2,7 @@ use crate::core_types::Variant;
2
2
use crate :: object:: NewRef ;
3
3
use crate :: private:: get_api;
4
4
use crate :: sys;
5
+ use std:: cmp:: Ordering ;
5
6
6
7
use std:: ffi:: CStr ;
7
8
use std:: fmt;
@@ -728,3 +729,47 @@ godot_test!(test_string {
728
729
assert_eq!( fmt2, GodotString :: from( "foo bar" ) ) ;
729
730
assert_eq!( fmt_string2, GodotString :: from( "{0} {1}" ) ) ;
730
731
} ) ;
732
+
733
+ godot_test ! ( test_string_name_eq {
734
+ use crate :: core_types:: { GodotString , StringName } ;
735
+
736
+ let a: StringName = StringName :: from_str( "some string" ) ;
737
+ let b: StringName = StringName :: from_godot_string( & GodotString :: from( "some string" ) ) ;
738
+ let c: StringName = StringName :: from_str( String :: from( "some other string" ) ) ;
739
+ let d: StringName = StringName :: from_str( "yet another one" ) ;
740
+
741
+ // test Eq
742
+ assert_eq!( a, b) ;
743
+ assert_ne!( a, c) ;
744
+ assert_ne!( a, d) ;
745
+ assert_ne!( b, c) ;
746
+ assert_ne!( b, d) ;
747
+ assert_ne!( c, d) ;
748
+
749
+ let back = b. to_godot_string( ) ;
750
+ assert_eq!( back, GodotString :: from( "some string" ) ) ;
751
+ } ) ;
752
+
753
+ godot_test ! ( test_string_name_ord {
754
+ use crate :: core_types:: { GodotString , StringName } ;
755
+
756
+ let a: StringName = StringName :: from_str( "some string" ) ;
757
+ let b: StringName = StringName :: from_godot_string( & GodotString :: from( "some string" ) ) ;
758
+ let c: StringName = StringName :: from_str( String :: from( "some other string" ) ) ;
759
+
760
+ // test Ord
761
+ let a_b = Ord :: cmp( & a, & b) ;
762
+ let b_a = Ord :: cmp( & b, & a) ;
763
+ assert_eq!( a_b, Ordering :: Equal ) ;
764
+ assert_eq!( b_a, Ordering :: Equal ) ;
765
+
766
+ let a_c = Ord :: cmp( & a, & c) ;
767
+ let c_a = Ord :: cmp( & c, & a) ;
768
+ let b_c = Ord :: cmp( & b, & c) ;
769
+ let c_b = Ord :: cmp( & c, & b) ;
770
+ assert_ne!( a_c, Ordering :: Equal ) ;
771
+ assert_eq!( a_c, b_c) ;
772
+ assert_eq!( c_a, c_b) ;
773
+ assert_eq!( a_c, c_a. reverse( ) ) ;
774
+ assert_eq!( b_c, c_b. reverse( ) ) ;
775
+ } ) ;
0 commit comments