summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Lamparski <diagonaldevice@gmail.com>2018-04-18 16:48:34 -0400
committerAlex Crichton <alex@alexcrichton.com>2018-04-21 17:04:01 -0700
commitbbfc486d112a9e601f6b1afeb7660c8ba015c849 (patch)
tree0bca205af3054f70171a3107053ee8836ea5acb2 /src
parent7ef7f38d5ee330605ddbb977ac90a1a1a2744e70 (diff)
fix my unit test that was horrendously wrong
and add one for non-mut slicing since I touched that method too
Diffstat (limited to 'src')
-rw-r--r--src/liballoc/tests/str.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs
index d1b348589a5..5bfb3fce849 100644
--- a/src/liballoc/tests/str.rs
+++ b/src/liballoc/tests/str.rs
@@ -402,11 +402,25 @@ 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]
@@ -414,7 +428,7 @@ fn test_str_slicemut_rangetoinclusive_ok() {
 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]