File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -586,6 +586,18 @@ pub enum RangePropertyValue<T: alloc::fmt::Debug + PartialEq> {
586586 Mixed ,
587587}
588588
589+ impl < T : alloc:: fmt:: Debug + PartialEq > RangePropertyValue < Option < T > > {
590+ pub fn map < U : alloc:: fmt:: Debug + PartialEq > (
591+ self ,
592+ f : impl FnOnce ( T ) -> U ,
593+ ) -> RangePropertyValue < Option < U > > {
594+ match self {
595+ Self :: Single ( value) => RangePropertyValue :: Single ( value. map ( f) ) ,
596+ Self :: Mixed => RangePropertyValue :: Mixed ,
597+ }
598+ }
599+ }
600+
589601#[ derive( Clone , Copy ) ]
590602pub struct Range < ' a > {
591603 pub ( crate ) node : Node < ' a > ,
@@ -2568,4 +2580,21 @@ mod tests {
25682580 let node = state. node_by_id ( NodeId ( 1 ) ) . unwrap ( ) ;
25692581 let _ = node. text_selection ( ) . unwrap ( ) ;
25702582 }
2583+
2584+ #[ test]
2585+ fn range_property_value_map ( ) {
2586+ use super :: RangePropertyValue ;
2587+ assert_eq ! (
2588+ RangePropertyValue :: Single ( Some ( 0 ) ) . map( |x| x + 1 ) ,
2589+ RangePropertyValue :: Single ( Some ( 1 ) )
2590+ ) ;
2591+ assert_eq ! (
2592+ RangePropertyValue :: <Option <usize >>:: Single ( None ) . map( |x| x + 1 ) ,
2593+ RangePropertyValue :: Single ( None )
2594+ ) ;
2595+ assert_eq ! (
2596+ RangePropertyValue :: <Option <usize >>:: Mixed . map( |x| x + 1 ) ,
2597+ RangePropertyValue :: Mixed
2598+ ) ;
2599+ }
25712600}
You can’t perform that action at this time.
0 commit comments