@@ -731,6 +731,100 @@ public void DetermineDirection(string? testStr, TextDirection expectedDirection)
731731 }
732732 #endregion
733733
734+ #region CompareTo tests
735+ private static IEnumerable < object [ ] > CompareToTestData =>
736+ [
737+ [ "" , "" , 0 ] ,
738+ [ "a" , "a" , 0 ] ,
739+ [ "a" , "b" , - 1 ] ,
740+ [ "b" , "a" , 1 ] ,
741+ [ "ab" , "abc" , - 1 ] ,
742+ [ "abc" , "ab" , 1 ] ,
743+ [ "abc" , "ABC" , 1 ]
744+ ] ;
745+
746+ [ TestMethod ]
747+ [ DynamicData ( nameof ( CompareToTestData ) ) ]
748+ public void CompareTo ( string string1 , string string2 , int expectedResult )
749+ {
750+ UString us1 = new ( string1 ) ;
751+ UString us2 = new ( string2 ) ;
752+
753+ switch ( expectedResult )
754+ {
755+ case > 0 :
756+ Assert . IsGreaterThan ( 0 , us1 . CompareTo ( us2 ) ) ;
757+ Assert . IsGreaterThan ( 0 , ( ( IComparable ) us1 ) . CompareTo ( us2 ) ) ;
758+ break ;
759+ case < 0 :
760+ Assert . IsLessThan ( 0 , us1 . CompareTo ( us2 ) ) ;
761+ Assert . IsLessThan ( 0 , ( ( IComparable ) us1 ) . CompareTo ( us2 ) ) ;
762+ break ;
763+ default :
764+ Assert . AreEqual ( 0 , us1 . CompareTo ( us2 ) ) ;
765+ Assert . AreEqual ( 0 , ( ( IComparable ) us1 ) . CompareTo ( us2 ) ) ;
766+ break ;
767+ }
768+ }
769+ #endregion
770+
771+ #region Clone tests
772+ [ TestMethod ]
773+ public void Clone ( )
774+ {
775+ UString original = new ( "test" ) ;
776+ object cloned = original . Clone ( ) ;
777+
778+ Assert . IsInstanceOfType ( cloned , typeof ( UString ) ) ;
779+ Assert . AreEqual ( original , cloned ) ;
780+ Assert . AreNotSame ( original , cloned ) ; // Should be different objects
781+ }
782+
783+ [ TestMethod ]
784+ public void Clone_Substring ( )
785+ {
786+ UString original = CreateTestSubstring ( "test" ) ;
787+ object cloned = original . Clone ( ) ;
788+
789+ Assert . IsInstanceOfType ( cloned , typeof ( UString ) ) ;
790+ Assert . AreEqual ( original , cloned ) ;
791+ Assert . AreNotSame ( original , cloned ) ; // Should be different objects
792+
793+ UString expected = new ( "test" ) ;
794+ Assert . AreEqual ( expected , cloned ) ;
795+ }
796+ #endregion
797+
798+ #region GetHashCode tests
799+ private static IEnumerable < object [ ] > GetHashCodeTestData =>
800+ [
801+ [ "" ] ,
802+ [ "a" ] ,
803+ [ "ab" ] ,
804+ [ "Hello" ] ,
805+ [ "😁🤔😮" ]
806+ ] ;
807+
808+ [ TestMethod ]
809+ [ DynamicData ( nameof ( GetHashCodeTestData ) ) ]
810+ public void GetHashCode ( string testString )
811+ {
812+ UString us1 = new ( testString ) ;
813+
814+ // Test that GetHash code for same content is consistent
815+ int hash1 = us1 . GetHashCode ( ) ;
816+ int hash2 = us1 . GetHashCode ( ) ;
817+ Assert . AreEqual ( hash1 , hash2 ) ; // Same instance should always give same hash
818+
819+ UString us2 = new ( testString ) ;
820+ Assert . AreEqual ( hash1 , us2 . GetHashCode ( ) ) ; // Same contents should always give same hash
821+
822+ // For different strings with same content (substring vs full), the hash should be same
823+ UString sub = CreateTestSubstring ( testString ) ;
824+ Assert . AreEqual ( us1 . GetHashCode ( ) , sub . GetHashCode ( ) ) ;
825+ }
826+ #endregion
827+
734828 #region Normalization tests
735829 [ TestMethod ]
736830 public void Normalization_FormC ( )
0 commit comments