@@ -539,5 +539,108 @@ public static void CustomEncoderClass()
539539            text  =  JsonEncodedText . Encode ( message ,  new  CustomEncoderAllowingPlusSign ( ) ) ; 
540540            Assert . Equal ( "a+" ,  text . Value ) ; 
541541        } 
542+ 
543+         [ Fact ] 
544+         public  static void  EncodeEmptySpan ( ) 
545+         { 
546+             JsonEncodedText  text  =  JsonEncodedText . Encode ( ReadOnlySpan < char > . Empty ) ; 
547+             Assert . True ( text . EncodedUtf8Bytes . IsEmpty ) ; 
548+             Assert . Equal ( "" ,  text . Value ) ; 
549+             Assert . Equal ( "" ,  text . ToString ( ) ) ; 
550+             Assert . Equal ( 0 ,  text . GetHashCode ( ) ) ; 
551+         } 
552+ 
553+         [ Fact ] 
554+         public  static void  EncodeEmptyUtf8Span ( ) 
555+         { 
556+             JsonEncodedText  text  =  JsonEncodedText . Encode ( ReadOnlySpan < byte > . Empty ) ; 
557+             Assert . True ( text . EncodedUtf8Bytes . IsEmpty ) ; 
558+             Assert . Equal ( "" ,  text . Value ) ; 
559+             Assert . Equal ( "" ,  text . ToString ( ) ) ; 
560+             Assert . Equal ( 0 ,  text . GetHashCode ( ) ) ; 
561+         } 
562+ 
563+         [ Fact ] 
564+         public  static void  EncodedUtf8BytesProperty ( ) 
565+         { 
566+             string  message  =  "Hello" ; 
567+             JsonEncodedText  text  =  JsonEncodedText . Encode ( message ) ; 
568+             
569+             ReadOnlySpan < byte >  bytes  =  text . EncodedUtf8Bytes ; 
570+             Assert . False ( bytes . IsEmpty ) ; 
571+             Assert . Equal ( Encoding . UTF8 . GetBytes ( message ) ,  bytes . ToArray ( ) ) ; 
572+         } 
573+ 
574+         [ Fact ] 
575+         public  static void  EqualsWithDifferentObjectType ( ) 
576+         { 
577+             JsonEncodedText  text  =  JsonEncodedText . Encode ( "test" ) ; 
578+             
579+             Assert . False ( text . Equals ( "test" ) ) ; 
580+             Assert . False ( text . Equals ( 42 ) ) ; 
581+             Assert . False ( text . Equals ( new  object ( ) ) ) ; 
582+         } 
583+ 
584+         [ Fact ] 
585+         public  static void  HashCodeConsistency ( ) 
586+         { 
587+             string  message  =  "consistent" ; 
588+             JsonEncodedText  text1  =  JsonEncodedText . Encode ( message ) ; 
589+             JsonEncodedText  text2  =  JsonEncodedText . Encode ( message ) ; 
590+             
591+             int  hash1  =  text1 . GetHashCode ( ) ; 
592+             int  hash2  =  text2 . GetHashCode ( ) ; 
593+             int  hash1Again  =  text1 . GetHashCode ( ) ; 
594+             
595+             Assert . Equal ( hash1 ,  hash2 ) ; 
596+             Assert . Equal ( hash1 ,  hash1Again ) ; 
597+         } 
598+ 
599+         [ Fact ] 
600+         public  static void  EncodeWithEscapingRequired ( ) 
601+         { 
602+             string  message  =  "line1\n line2" ; 
603+             JsonEncodedText  text  =  JsonEncodedText . Encode ( message ) ; 
604+             
605+             Assert . Contains ( "\\ n" ,  text . Value ) ; 
606+             Assert . NotEqual ( message ,  text . Value ) ; 
607+         } 
608+ 
609+         [ Fact ] 
610+         public  static void  EncodeUtf8WithEscapingRequired ( ) 
611+         { 
612+             byte [ ]  utf8Message  =  Encoding . UTF8 . GetBytes ( "test\" value" ) ; 
613+             JsonEncodedText  text  =  JsonEncodedText . Encode ( utf8Message ) ; 
614+             
615+             Assert . Contains ( "\\ u0022" ,  text . Value ) ; 
616+         } 
617+ 
618+         [ Theory ] 
619+         [ InlineData ( "abc" ) ] 
620+         [ InlineData ( "Hello World" ) ] 
621+         [ InlineData ( "123" ) ] 
622+         public  static void  EncodeSpanMatchesString ( string  message ) 
623+         { 
624+             JsonEncodedText  textFromString  =  JsonEncodedText . Encode ( message ) ; 
625+             JsonEncodedText  textFromSpan  =  JsonEncodedText . Encode ( message . AsSpan ( ) ) ; 
626+             
627+             Assert . Equal ( textFromString . Value ,  textFromSpan . Value ) ; 
628+             Assert . True ( textFromString . Equals ( textFromSpan ) ) ; 
629+             Assert . Equal ( textFromString . GetHashCode ( ) ,  textFromSpan . GetHashCode ( ) ) ; 
630+         } 
631+ 
632+         [ Theory ] 
633+         [ InlineData ( "abc" ) ] 
634+         [ InlineData ( "Hello World" ) ] 
635+         [ InlineData ( "123" ) ] 
636+         public  static void  EncodeUtf8MatchesString ( string  message ) 
637+         { 
638+             JsonEncodedText  textFromString  =  JsonEncodedText . Encode ( message ) ; 
639+             JsonEncodedText  textFromUtf8  =  JsonEncodedText . Encode ( Encoding . UTF8 . GetBytes ( message ) ) ; 
640+             
641+             Assert . Equal ( textFromString . Value ,  textFromUtf8 . Value ) ; 
642+             Assert . True ( textFromString . Equals ( textFromUtf8 ) ) ; 
643+             Assert . Equal ( textFromString . GetHashCode ( ) ,  textFromUtf8 . GetHashCode ( ) ) ; 
644+         } 
542645    } 
543646} 
0 commit comments