From 57099de38aa066f52ee0bb6e6b717ba5e80c5820 Mon Sep 17 00:00:00 2001 From: Rushmore75 Date: Wed, 12 Nov 2025 15:18:45 -0700 Subject: [PATCH] working on #19 --- src/app/logic/calc.rs | 27 +++++++++++++++++++++++---- src/app/logic/ctx.rs | 5 ++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/app/logic/calc.rs b/src/app/logic/calc.rs index f90045d..bad40e1 100644 --- a/src/app/logic/calc.rs +++ b/src/app/logic/calc.rs @@ -2,7 +2,7 @@ use std::{ fmt::Display, fs, io::{Read, Write}, - path::PathBuf, + path::PathBuf, sync::RwLock, }; use evalexpr::*; @@ -82,7 +82,6 @@ impl Grid { Ok(()) } - #[must_use] pub fn max_y_at_x(&self, x: usize) -> usize { let mut max_y = 0; @@ -315,8 +314,7 @@ impl Grid { // FIXME this might be a dangerous recursion, as I don't think its bounded right now return self.evaluate(&new_eq) } - // panic!("Will not be able to parse this equation, cell {e} not found") - return Err(format!("{var_not_found} is not a variable")); + return Err(format!("\"{var_not_found}\" is not a variable")); } EvalexprError::TypeError { expected: e, @@ -415,6 +413,7 @@ impl Default for Grid { } } +#[derive(Debug)] pub enum CellType { Number(f64), String(String), @@ -704,5 +703,25 @@ fn parse_csv() { // starting with a quote with a comma assert_eq!(Grid::parse_csv_line("\"\"\"hello, world\"\" is what she said\",1"), vec![Some("\"hello, world\" is what she said".to_string()), Some("1".to_string())]); +} + +#[test] +fn ranges() { + let mut grid = Grid::new(); + + grid.set_cell("A0", 2.); + grid.set_cell("A1", 1.); + grid.set_cell("B0", "=sum(A:A)".to_string()); + + let cell = grid.get_cell("B0").as_ref().expect("Just set it"); + let res = grid.evaluate(&cell.to_string()).expect("Should evaluate."); + assert_eq!(res, 3.); + + grid.set_cell("B1", "=B0*2".to_string()); + + // cell math + let cell = grid.get_cell("B1").as_ref().expect("Just set it"); + let res = grid.evaluate(&cell.to_string()).expect("Should evaluate."); + assert_eq!(res, 6.); } \ No newline at end of file diff --git a/src/app/logic/ctx.rs b/src/app/logic/ctx.rs index fbc0020..edf48ad 100644 --- a/src/app/logic/ctx.rs +++ b/src/app/logic/ctx.rs @@ -75,14 +75,17 @@ impl<'a> CallbackContext<'a> { } } + #[allow(dead_code)] pub fn clear_variables(&mut self) { () } + #[allow(dead_code)] pub fn clear_functions(&mut self) { - self.functions.clear() + () } + #[allow(dead_code)] pub fn clear(&mut self) { self.clear_variables(); self.clear_functions();