File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -401,20 +401,34 @@ fn test_str_get_maxinclusive() {
401401 }
402402}
403403
404+ #[ test]
405+ fn test_str_slice_rangetoinclusive_ok ( ) {
406+ let s = "abcαβγ" ;
407+ assert_eq ! ( & s[ ..=2 ] , "abc" ) ;
408+ assert_eq ! ( & s[ ..=4 ] , "abcα" ) ;
409+ }
410+
411+ #[ test]
412+ #[ should_panic]
413+ fn test_str_slice_rangetoinclusive_notok ( ) {
414+ let s = "abcαβγ" ;
415+ & s[ ..=3 ] ;
416+ }
417+
404418#[ test]
405419fn test_str_slicemut_rangetoinclusive_ok ( ) {
406420 let mut s = "abcαβγ" . to_owned ( ) ;
407421 let s: & mut str = & mut s;
408- & mut s[ ..=3 ] ; // before alpha
409- & mut s[ ..=5 ] ; // after alpha
422+ assert_eq ! ( & mut s[ ..=2 ] , "abc" ) ;
423+ assert_eq ! ( & mut s[ ..=4 ] , "abcα" ) ;
410424}
411425
412426#[ test]
413427#[ should_panic]
414428fn test_str_slicemut_rangetoinclusive_notok ( ) {
415429 let mut s = "abcαβγ" . to_owned ( ) ;
416430 let s: & mut str = & mut s;
417- & mut s[ ..=4 ] ; // middle of alpha, which is 2 bytes long
431+ & mut s[ ..=3 ] ;
418432}
419433
420434#[ test]
You can’t perform that action at this time.
0 commit comments