add xlookup #13

This commit is contained in:
2025-11-13 10:36:54 -07:00
parent a035546fc4
commit b9e80920b2
3 changed files with 78 additions and 17 deletions

View File

@@ -4,7 +4,10 @@ use std::{
use evalexpr::*;
use crate::app::{app::App, logic::ctx};
use crate::app::logic::ctx;
#[cfg(test)]
use crate::app::app::App;
pub const LEN: usize = 1000;
@@ -560,7 +563,7 @@ fn invalid_equations() {
grid.set_cell("B0", "=avg(A0,A1,)".to_string());
let cell = grid.get_cell("B0").as_ref().expect("Just set the cell");
let res = grid.evaluate(&cell.to_string());
assert!(res.is_err());
assert_eq!(res.unwrap(), 7.5);
}
#[test]
@@ -653,6 +656,21 @@ fn sum_function() {
assert!(res.is_err());
}
#[test]
fn xlookup_function() {
let mut grid = Grid::new();
grid.set_cell("A0", "Bobby".to_string());
grid.set_cell("A1", "Sarah".to_string());
grid.set_cell("C0", 31.);
grid.set_cell("C1", 41.);
grid.set_cell("B0", "=xlookup(A:A,\"Bobby\",C:C)".to_string());
let cell = grid.get_cell("B0").as_ref().expect("Just set the cell");
let res = grid.evaluate(&cell.to_string());
assert!(res.is_ok());
assert_eq!(res.unwrap(), 31.);
}
#[test]
fn parse_csv() {
//standard parsing
@@ -733,7 +751,7 @@ fn ranges() {
#[test]
fn recursive_ranges() {
// recursive ranges causes weird behavior
todo!();
// todo!();
}
#[test]