@@ -569,4 +569,34 @@ mod tests {
569569 check ( "hello \\ \r \n world" , b"hello world" ) ;
570570 check ( "thread's" , b"thread's" )
571571 }
572+
573+ #[ test]
574+ fn test_unescape_raw_str ( ) {
575+ fn check ( literal : & str , expected : & [ ( Range < usize > , Result < char , EscapeError > ) ] ) {
576+ let mut unescaped = Vec :: with_capacity ( literal. len ( ) ) ;
577+ unescape_raw_str ( literal, & mut |range, res| unescaped. push ( ( range, res) ) ) ;
578+ assert_eq ! ( unescaped, expected) ;
579+ }
580+
581+ check ( "\r \n " , & [ ( 0 ..2 , Ok ( '\n' ) ) ] ) ;
582+ check ( "\r " , & [ ( 0 ..1 , Err ( EscapeError :: BareCarriageReturnInRawString ) ) ] ) ;
583+ check ( "\r x" , & [ ( 0 ..1 , Err ( EscapeError :: BareCarriageReturnInRawString ) ) , ( 1 ..2 , Ok ( 'x' ) ) ] ) ;
584+ }
585+
586+ #[ test]
587+ fn test_unescape_raw_byte_str ( ) {
588+ fn check ( literal : & str , expected : & [ ( Range < usize > , Result < u8 , EscapeError > ) ] ) {
589+ let mut unescaped = Vec :: with_capacity ( literal. len ( ) ) ;
590+ unescape_raw_byte_str ( literal, & mut |range, res| unescaped. push ( ( range, res) ) ) ;
591+ assert_eq ! ( unescaped, expected) ;
592+ }
593+
594+ check ( "\r \n " , & [ ( 0 ..2 , Ok ( byte_from_char ( '\n' ) ) ) ] ) ;
595+ check ( "\r " , & [ ( 0 ..1 , Err ( EscapeError :: BareCarriageReturnInRawString ) ) ] ) ;
596+ check ( "🦀" , & [ ( 0 ..4 , Err ( EscapeError :: NonAsciiCharInByteString ) ) ] ) ;
597+ check (
598+ "🦀a" ,
599+ & [ ( 0 ..4 , Err ( EscapeError :: NonAsciiCharInByteString ) ) , ( 4 ..5 , Ok ( byte_from_char ( 'a' ) ) ) ] ,
600+ ) ;
601+ }
572602}
0 commit comments