From 4aab669963a16a7906a7403ce6507b0dd4acfd07 Mon Sep 17 00:00:00 2001 From: bsbds <69835502+bsbds@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:08:25 +0800 Subject: [PATCH] test: add test for conversion from KeyRange Signed-off-by: bsbds <69835502+bsbds@users.noreply.github.com> --- crates/utils/src/interval_map/mod.rs | 5 +++-- crates/xlineapi/src/interval.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/utils/src/interval_map/mod.rs b/crates/utils/src/interval_map/mod.rs index be66f3337..d03297c3e 100644 --- a/crates/utils/src/interval_map/mod.rs +++ b/crates/utils/src/interval_map/mod.rs @@ -980,11 +980,12 @@ where /// The Interval stored in `IntervalMap` /// Represents the interval [low, high) #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[non_exhaustive] pub struct Interval { /// Low value - low: T, + pub low: T, /// high value - high: T, + pub high: T, } impl Interval { diff --git a/crates/xlineapi/src/interval.rs b/crates/xlineapi/src/interval.rs index 3a55376b4..b9ec0e643 100644 --- a/crates/xlineapi/src/interval.rs +++ b/crates/xlineapi/src/interval.rs @@ -72,4 +72,16 @@ mod tests { assert!(BytesAffine::new_key("abcd") < BytesAffine::new_unbounded()); assert_eq!(BytesAffine::new_unbounded(), BytesAffine::new_unbounded()); } + + #[test] + fn convert_from_key_range_is_ok() { + let range0 = KeyRange::new("a", "e"); + let range1 = KeyRange::new_one_key("f"); + let interval0: Interval = range0.into(); + let interval1: Interval = range1.into(); + assert_eq!(interval0.low, BytesAffine::new_key("a")); + assert_eq!(interval0.high, BytesAffine::new_key("e")); + assert_eq!(interval1.low, BytesAffine::new_key("f")); + assert_eq!(interval1.high, BytesAffine::new_key("f\0")); + } }