assert_eq!(c2.next(), None);
}
+#[test]
+fn test_windows_nth_back() {
+ let v: &[i32] = &[0, 1, 2, 3, 4, 5];
+ let mut c = v.windows(2);
+ assert_eq!(c.nth_back(2).unwrap()[0], 2);
+ assert_eq!(c.next_back().unwrap()[1], 2);
+
+ let v2: &[i32] = &[0, 1, 2, 3, 4];
+ let mut c2 = v2.windows(4);
+ assert_eq!(c2.nth_back(1).unwrap()[1], 1);
+ assert_eq!(c2.next_back(), None);
+}
+
#[test]
fn test_windows_last() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
// to be used in `should_panic`)
#[test]
#[should_panic(expected = "out of range")]
+ #[cfg(not(miri))]
fn assert_range_eq_can_fail_by_panic() {
assert_range_eq!([0, 1, 2], 0..5, [0, 1, 2]);
}
// to be used in `should_panic`)
#[test]
#[should_panic(expected = "==")]
+ #[cfg(not(miri))]
fn assert_range_eq_can_fail_by_inequality() {
assert_range_eq!([0, 1, 2], 0..2, [0, 1, 2]);
}
#[test]
#[should_panic(expected = $expect_msg)]
+ #[cfg(not(miri))]
fn index_fail() {
let v = $data;
let v: &[_] = &v;
#[test]
#[should_panic(expected = $expect_msg)]
+ #[cfg(not(miri))]
fn index_mut_fail() {
let mut v = $data;
let v: &mut [_] = &mut v;
#[test]
#[cfg(not(target_arch = "wasm32"))]
+#[cfg(not(miri))]
fn sort_unstable() {
use core::cmp::Ordering::{Equal, Greater, Less};
use core::slice::heapsort;
}
#[test]
+#[cfg(not(miri))]
fn test_align_to_simple() {
let bytes = [1u8, 2, 3, 4, 5, 6, 7];
let (prefix, aligned, suffix) = unsafe { bytes.align_to::<u16>() };
}
#[test]
+#[cfg(not(miri))]
fn test_align_to_zst() {
let bytes = [1, 2, 3, 4, 5, 6, 7];
let (prefix, aligned, suffix) = unsafe { bytes.align_to::<()>() };
}
#[test]
+#[cfg(not(miri))]
fn test_align_to_non_trivial() {
#[repr(align(8))] struct U64(u64, u64);
#[repr(align(8))] struct U64U64U32(u64, u64, u32);
}
#[test]
+#[cfg(not(miri))]
fn test_align_to_empty_mid() {
use core::mem;
#[test]
#[should_panic(expected = "src is out of bounds")]
+#[cfg(not(miri))]
fn test_copy_within_panics_src_too_long() {
let mut bytes = *b"Hello, World!";
// The length is only 13, so 14 is out of bounds.
#[test]
#[should_panic(expected = "dest is out of bounds")]
+#[cfg(not(miri))]
fn test_copy_within_panics_dest_too_long() {
let mut bytes = *b"Hello, World!";
// The length is only 13, so a slice of length 4 starting at index 10 is out of bounds.
}
#[test]
#[should_panic(expected = "src end is before src start")]
+#[cfg(not(miri))]
fn test_copy_within_panics_src_inverted() {
let mut bytes = *b"Hello, World!";
// 2 is greater than 1, so this range is invalid.
bytes.copy_within(2..1, 0);
}
+
+#[test]
+fn test_is_sorted() {
+ let empty: [i32; 0] = [];
+
+ assert!([1, 2, 2, 9].is_sorted());
+ assert!(![1, 3, 2].is_sorted());
+ assert!([0].is_sorted());
+ assert!(empty.is_sorted());
+ assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
+ assert!([-2, -1, 0, 3].is_sorted());
+ assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
+ assert!(!["c", "bb", "aaa"].is_sorted());
+ assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
+}