use spreadsheet_ods_cellref::refs_format::{fmt_col_name, fmt_row_name}; use spreadsheet_ods_cellref::refs_parser::{try_u32_from_colname, try_u32_from_rowname, Span}; use spreadsheet_ods_cellref::tokens::{col, row}; use std::fmt; use std::fmt::{Debug, Display, Formatter, Write}; 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_parse() { fn rowname(row: u32) -> String { let mut row_str = String::new(); write!(row_str, "{}", Fmt(|f| fmt_row_name(f, row))).unwrap(); row_str } fn colname(col: u32) -> String { let mut col_str = String::new(); write!(col_str, "{}", Fmt(|f| fmt_col_name(f, col))).unwrap(); col_str } for i in 0..704 { let cn = colname(i); let (rest, (_abs, cc)) = col(Span::new(cn.as_str())).unwrap(); assert_eq!(i, try_u32_from_colname(cc).unwrap()); assert_eq!("", *rest); } for i in 0..101 { let cn = rowname(i); let (rest, (_abs, cr)) = row(Span::new(cn.as_str())).unwrap(); assert_eq!(i, try_u32_from_rowname(cr).unwrap()); assert_eq!("", *rest); } let (rest, (_abs, c)) = col(Span::new("A32")).unwrap(); assert_eq!("A", *c); assert_eq!("32", *rest); let cn = Span::new("AAAA32 "); let (rest, (_abs, cc)) = col(cn).unwrap(); assert_eq!("AAAA", *cc); assert_eq!("32 ", *rest); let (rest, (_abs, cr)) = row(rest).unwrap(); assert_eq!("32", *cr); assert_eq!(" ", *rest); }