Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions consumer/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,18 @@ pub enum RangePropertyValue<T: alloc::fmt::Debug + PartialEq> {
Mixed,
}

impl<T: alloc::fmt::Debug + PartialEq> RangePropertyValue<Option<T>> {
pub fn map<U: alloc::fmt::Debug + PartialEq>(
self,
f: impl FnOnce(T) -> U,
) -> RangePropertyValue<Option<U>> {
match self {
Self::Single(value) => RangePropertyValue::Single(value.map(f)),
Self::Mixed => RangePropertyValue::Mixed,
}
}
}

#[derive(Clone, Copy)]
pub struct Range<'a> {
pub(crate) node: Node<'a>,
Expand Down Expand Up @@ -2287,4 +2299,21 @@ mod tests {
let node = state.node_by_id(NodeId(1)).unwrap();
let _ = node.text_selection().unwrap();
}

#[test]
fn range_property_value_map() {
use super::RangePropertyValue;
assert_eq!(
RangePropertyValue::Single(Some(0)).map(|x| x + 1),
RangePropertyValue::Single(Some(1))
);
assert_eq!(
RangePropertyValue::<Option<usize>>::Single(None).map(|x| x + 1),
RangePropertyValue::Single(None)
);
assert_eq!(
RangePropertyValue::<Option<usize>>::Mixed.map(|x| x + 1),
RangePropertyValue::Mixed
);
}
}