From fbd92183841633507f71eb305824c6d5c0edf215 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 29 Jul 2023 14:15:47 +0200 Subject: [PATCH] dd regression tests for #236 --- src/slice/tests.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/slice/tests.rs b/src/slice/tests.rs index edcb7a6c..feb2584b 100644 --- a/src/slice/tests.rs +++ b/src/slice/tests.rs @@ -75,6 +75,31 @@ fn copying() { } } +// regression tests for #236 +#[test] +fn copy_within_supports_empty_ranges() { + let empty = bits![mut u8, Lsb0; 0; 0]; + empty.copy_within(0..0, 0); + assert_eq!(empty, bits![]); + + let non_empty = bits![mut u8, Lsb0; 0; 3]; + non_empty.copy_within(2..2, 0); + assert_eq!(non_empty, bits![0, 0, 0]); +} +#[test] +#[should_panic] +fn copy_within_panics_if_empty_range_exceeds_bounds() { + let empty_slice = bits![mut u8, Lsb0; 0; 0]; + empty_slice.copy_within(2..2, 0); +} +#[test] +#[should_panic] +fn copy_within_panics_if_dest_for_empty_range_exceeds_bounds() { + let empty_slice = bits![mut u8, Lsb0; 0; 0]; + empty_slice.copy_within(0..0, 1); +} + + #[test] fn writing() { let bits = bits![mut 0; 2];