use spreadsheet_ods_cellref::refs_parser::{ parse_cell_range, parse_cell_range_list, parse_cell_ref, Span, }; use spreadsheet_ods_cellref::{CellRange, CellRef}; use std::fmt; use std::fmt::{Debug, Display, Formatter}; pub(crate) struct Fmt(pub F) where for<'a> F: Fn(&mut Formatter<'a>) -> fmt::Result; impl Debug for Fmt where for<'a> F: Fn(&mut Formatter<'a>) -> fmt::Result, { /// Calls f with the given Formatter. fn fmt<'a>(&self, f: &mut Formatter<'a>) -> fmt::Result { (self.0)(f) } } impl Display for Fmt where for<'a> F: Fn(&mut Formatter<'a>) -> fmt::Result, { /// Calls f with the given Formatter. fn fmt<'a>(&self, f: &mut Formatter<'a>) -> fmt::Result { (self.0)(f) } } #[test] fn test_cellref() { let (_, (cr, _)) = parse_cell_ref(Span::new(".A3")).unwrap(); assert_eq!(cr, CellRef::local(2, 0)); let (_, (cr, _)) = parse_cell_ref(Span::new(".$A3")).unwrap(); assert_eq!(cr, CellRef::new_all(None, None, false, 2, true, 0)); let (_, (cr, _)) = parse_cell_ref(Span::new(".A$3")).unwrap(); assert_eq!(cr, CellRef::new_all(None, None, true, 2, false, 0)); let (_, (cr, _)) = parse_cell_ref(Span::new("fufufu.A3")).unwrap(); assert_eq!( cr, CellRef::new_all(None, Some("fufufu".to_string()), false, 2, false, 0) ); let (_, (cr, _)) = parse_cell_ref(Span::new("'lak.moi'.A3")).unwrap(); assert_eq!( cr, CellRef::new_all(None, Some("lak.moi".to_string()), false, 2, false, 0) ); let (_, (cr, _)) = parse_cell_ref(Span::new("'lak''moi'.A3")).unwrap(); assert_eq!( cr, CellRef::new_all(None, Some("lak'moi".to_string()), false, 2, false, 0) ); let (_, (cr, _)) = parse_cell_ref(Span::new("****.B4")).unwrap(); assert_eq!( cr, CellRef::new_all(None, Some("****".to_string()), false, 3, false, 1) ); } #[test] fn test_cellange() { let (_, (cr, _)) = parse_cell_range(Span::new(".A3:.F9")).unwrap(); assert_eq!( cr, CellRange::new_all(None, None, false, 2, false, 0, None, false, 8, false, 5) ); let (_, (cr, _)) = parse_cell_range(Span::new("table.A3:.F9")).unwrap(); assert_eq!( cr, CellRange::new_all( None, Some("table".to_string()), false, 2, false, 0, None, false, 8, false, 5 ) ); let (_, (cr, _)) = parse_cell_range(Span::new("table.A3:.F9")).unwrap(); assert_eq!( cr, CellRange::new_all( None, Some("table".to_string()), false, 2, false, 0, None, false, 8, false, 5 ) ); } #[test] fn test_cell_ranges() { let (_, Some(cr)) = parse_cell_range_list(Span::new("table.A3:.F9 table.A4:.F10")).unwrap() else {panic!()}; assert_eq!( cr, vec![ CellRange::remote("table", 2, 0, 8, 5), CellRange::remote("table", 3, 0, 9, 5), ] ); }