diff --git a/Cargo.lock b/Cargo.lock index 670bef9..c21e3bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -108,7 +108,7 @@ dependencies = [ [[package]] name = "range_bounds_map" -version = "0.1.0" +version = "0.1.1" dependencies = [ "either", "itertools", diff --git a/Cargo.toml b/Cargo.toml index 1d14eca..afe42c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "range_bounds_map" -version = "0.1.0" +version = "0.1.1" authors = ["James Forster "] edition = "2021" description = """ diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs index 401bcca..fe70d53 100644 --- a/src/range_bounds_map.rs +++ b/src/range_bounds_map.rs @@ -1952,7 +1952,18 @@ where } } - return result; + //only return valid range_bounds + return CutResult { + before_cut: result + .before_cut + .filter(|x| is_valid_range_bounds::<(Bound<&I>, Bound<&I>), I>(x)), + inside_cut: result + .inside_cut + .filter(|x| is_valid_range_bounds::<(Bound<&I>, Bound<&I>), I>(x)), + after_cut: result + .after_cut + .filter(|x| is_valid_range_bounds::<(Bound<&I>, Bound<&I>), I>(x)), + }; } #[trivial] @@ -2932,6 +2943,30 @@ mod tests { None => false, } } + #[test] + fn cut_range_bounds_should_return_valid_ranges() { + let result = cut_range_bounds(&(3..8), &(5..8)); + if let Some(x) = result.before_cut { + assert!(is_valid_range_bounds(&cloned_bounds(x))); + } + if let Some(x) = result.inside_cut { + assert!(is_valid_range_bounds(&cloned_bounds(x))); + } + if let Some(x) = result.after_cut { + assert!(is_valid_range_bounds(&cloned_bounds(x))); + } + + let result = cut_range_bounds(&(3..8), &(3..5)); + if let Some(x) = result.before_cut { + assert!(is_valid_range_bounds(&cloned_bounds(x))); + } + if let Some(x) = result.inside_cut { + assert!(is_valid_range_bounds(&cloned_bounds(x))); + } + if let Some(x) = result.after_cut { + assert!(is_valid_range_bounds(&cloned_bounds(x))); + } + } #[test] fn touches_tests() {