use crate::Slice;
#[test]
fn copy() {
let mut dst = [0u8; 4];
Slice::copy(&mut dst, &[1, 2, 3, 4]);
assert_eq!(dst, [1, 2, 3, 4]);
let mut empty_dest = [0u8; 0];
Slice::<u8>::copy(&mut empty_dest, &[]);
assert_eq!(empty_dest, [0u8; 0]);
const fn _const_test() {
let mut dst = [0u8; 2];
Slice::copy(&mut dst, &[1, 2]);
}
}
#[test]
#[should_panic]
fn copy_panic() {
let mut dst = [0u8; 3];
Slice::copy(&mut dst, &[1, 2, 3, 4]); }
#[test]
fn copy_array_at() {
let mut dst = [0u8; 5];
Slice::<u8>::copy_array_at(&mut dst, &[1, 2], 2);
assert_eq!(dst, [0, 0, 1, 2, 0]);
let mut dst = [0u8; 3];
Slice::<u8>::copy_array_at(&mut dst, &[1, 2, 3], 0);
assert_eq!(dst, [1, 2, 3]);
}
#[test]
fn copied_array_at() {
let result = Slice::<u8>::copied_array_at([0u8; 5], &[1, 2], 2);
assert_eq!(result, [0, 0, 1, 2, 0]);
let result = Slice::<u8>::copied_array_at([0u8; 3], &[1, 2, 3], 0);
assert_eq!(result, [1, 2, 3]);
assert_eq!(Slice::<u8>::copied_array_at([1u8; 3], &[], 1), [1, 1, 1]);
assert_eq!(Slice::<u8>::copied_array_at([0u8; 3], &[1, 2], 1), [0, 1, 2]);
const fn _const_test() -> [u8; 2] {
Slice::<u8>::copied_array_at([0u8; 2], &[1, 2], 0)
}
}
#[test]
#[should_panic]
fn copied_array_at_panic_overflow() {
Slice::<u8>::copied_array_at([0u8; 3], &[1, 2, 3, 4], 0); }
#[test]
#[should_panic]
fn copied_array_at_panic_overflow_offset() {
Slice::<u8>::copied_array_at([0u8; 3], &[1, 2], 2); }
#[test]
fn eq_slices() {
assert![Slice::<u8>::eq(&[1, 2], &[1, 2])];
assert![Slice::<&[u8]>::eq(&[&[1, 2], &[3, 4]], &[&[1, 2], &[3, 4]])];
assert![Slice::<u8>::eq(&[1, 2], &[1, 2])];
assert![Slice::<&[u8]>::eq(&[&[1, 2], &[3, 4]], &[&[1, 2], &[3, 4]])];
assert![Slice::<char>::eq(&['a', 'b'], &['a', 'b'])];
assert![Slice::<&[char]>::eq(&[&['a', 'b'], &['c', 'd']], &[&['a', 'b'], &['c', 'd']])];
assert![Slice::<&str>::eq(&"ab", "ab")];
assert![Slice::<&[&str]>::eq(&["ab", "cd"], &["ab", "cd"])];
}
#[test]
fn trim_leading() {
let data = b"0000123";
assert_eq!(Slice::trim_leading(data, b'0'), b"123");
assert_eq!(Slice::trim_leading_keep(data, b'0', 2), b"00123");
assert_eq!(Slice::trim_leading_min_len(b"000", b'0', 1), b"0");
assert_eq!(Slice::trim_leading_min_len(data, b'0', 0), b"123"); assert_eq!(Slice::trim_leading_min_len(data, b'0', 5), b"00123");
assert_eq!(Slice::trim_leading_min_len(data, b'0', 20), b"0000123"); }
#[test]
fn trim_edges() {
let data = b"000123000";
assert_eq!(Slice::trim_edges_min_len_left(data, b'0', 4), b"0123");
assert_eq!(Slice::trim_edges_min_len_left(data, b'0', 5), b"01230");
assert_eq!(Slice::trim_edges_min_len_left(data, b'0', 6), b"001230");
assert_eq!(Slice::trim_edges_min_len_left(data, b'0', 7), b"0012300");
assert_eq!(Slice::trim_edges_min_len_right(data, b'0', 4), b"1230");
assert_eq!(Slice::trim_edges_min_len_right(data, b'0', 5), b"01230");
assert_eq!(Slice::trim_edges_min_len_right(data, b'0', 6), b"012300");
assert_eq!(Slice::trim_edges_min_len_right(data, b'0', 7), b"0012300");
}
#[test]
fn replace() {
let mut data = [0, 0, 0, 0, 1, 2, 3];
Slice::replace_leading(&mut data, 0, 48);
assert_eq!(&data, &[48, 48, 48, 48, 1, 2, 3]);
}