@@ -578,4 +578,41 @@ mod tests {
578
578
const S : & CStr16 = cstr16 ! ( "ABC" ) ;
579
579
assert_eq ! ( S . to_u16_slice_with_nul( ) , [ 65 , 66 , 67 , 0 ] ) ;
580
580
}
581
+
582
+ /// Tests the trait implementation of trait [`EqStrUntilNul]` for [`CStr8`].
583
+ ///
584
+ /// This tests that `String` and `str` from the standard library can be
585
+ /// checked for equality against a [`CStr8`]. It checks both directions,
586
+ /// i.e., the equality is reflexive.
587
+ #[ test]
588
+ fn test_cstr8_eq_std_str ( ) {
589
+ let input: & CStr8 = cstr8 ! ( "test" ) ;
590
+
591
+ // test various comparisons with different order (left, right)
592
+ assert ! ( input. eq_str_until_nul( "test" ) ) ; // requires ?Sized constraint
593
+ assert ! ( input. eq_str_until_nul( & "test" ) ) ;
594
+ assert ! ( input. eq_str_until_nul( & String :: from( "test" ) ) ) ;
595
+
596
+ // now other direction
597
+ assert ! ( String :: from( "test" ) . eq_str_until_nul( input) ) ;
598
+ assert ! ( "test" . eq_str_until_nul( input) ) ;
599
+ }
600
+
601
+ /// Tests the trait implementation of trait [`EqStrUntilNul]` for [`CStr16`].
602
+ ///
603
+ /// This tests that `String` and `str` from the standard library can be
604
+ /// checked for equality against a [`CStr16`]. It checks both directions,
605
+ /// i.e., the equality is reflexive.
606
+ #[ test]
607
+ fn test_cstr16_eq_std_str ( ) {
608
+ let input: & CStr16 = cstr16 ! ( "test" ) ;
609
+
610
+ assert ! ( input. eq_str_until_nul( "test" ) ) ; // requires ?Sized constraint
611
+ assert ! ( input. eq_str_until_nul( & "test" ) ) ;
612
+ assert ! ( input. eq_str_until_nul( & String :: from( "test" ) ) ) ;
613
+
614
+ // now other direction
615
+ assert ! ( String :: from( "test" ) . eq_str_until_nul( input) ) ;
616
+ assert ! ( "test" . eq_str_until_nul( input) ) ;
617
+ }
581
618
}
0 commit comments