Skip to content

Commit 90b361b

Browse files
committed
fix my unit test that was horrendously wrong
and add one for non-mut slicing since I touched that method too
1 parent b74d692 commit 90b361b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/liballoc/tests/str.rs

+17-3
Original file line numberDiff line numberDiff 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]
405419
fn 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]
414428
fn 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]

0 commit comments

Comments
 (0)