Skip to content

Commit

Permalink
fix my unit test that was horrendously wrong
Browse files Browse the repository at this point in the history
and add one for non-mut slicing since I touched that method too
  • Loading branch information
ExpHP committed Apr 18, 2018
1 parent b74d692 commit 90b361b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/liballoc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,20 +401,34 @@ fn test_str_get_maxinclusive() {
}
}

#[test]
fn test_str_slice_rangetoinclusive_ok() {
let s = "abcαβγ";
assert_eq!(&s[..=2], "abc");
assert_eq!(&s[..=4], "abcα");
}

#[test]
#[should_panic]
fn test_str_slice_rangetoinclusive_notok() {
let s = "abcαβγ";
&s[..=3];
}

#[test]
fn test_str_slicemut_rangetoinclusive_ok() {
let mut s = "abcαβγ".to_owned();
let s: &mut str = &mut s;
&mut s[..=3]; // before alpha
&mut s[..=5]; // after alpha
assert_eq!(&mut s[..=2], "abc");
assert_eq!(&mut s[..=4], "abcα");
}

#[test]
#[should_panic]
fn test_str_slicemut_rangetoinclusive_notok() {
let mut s = "abcαβγ".to_owned();
let s: &mut str = &mut s;
&mut s[..=4]; // middle of alpha, which is 2 bytes long
&mut s[..=3];
}

#[test]
Expand Down

0 comments on commit 90b361b

Please sign in to comment.