add failing test
Some checks failed
Test Rust project / test (ubuntu-latest, stable) (push) Failing after 48s

This commit is contained in:
2026-02-07 19:30:08 -07:00
parent d983995e8f
commit 1825460074
2 changed files with 50 additions and 16 deletions

View File

@@ -270,9 +270,11 @@ impl Grid {
} }
} }
} }
pub fn insert_row_below(&mut self, (x, y): (usize, usize)) { pub fn insert_row_below(&mut self, (x, y): (usize, usize)) {
self.insert_row_above((x,y+1)); self.insert_row_above((x,y+1));
} }
pub fn insert_column_before(&mut self, (insertion_x, _y): (usize, usize)) { pub fn insert_column_before(&mut self, (insertion_x, _y): (usize, usize)) {
let mut v = Vec::with_capacity(LEN); let mut v = Vec::with_capacity(LEN);
for _ in 0..LEN { for _ in 0..LEN {
@@ -289,6 +291,7 @@ impl Grid {
// add 1 because of the insertion // add 1 because of the insertion
if arg_x < insertion_x { rolling.to_owned() } else { rolling.replace(old, new) } if arg_x < insertion_x { rolling.to_owned() } else { rolling.replace(old, new) }
} else { } else {
// FIXME could be a range
unimplemented!("Invalid variable wanted to be translated") unimplemented!("Invalid variable wanted to be translated")
} }
}) })
@@ -298,6 +301,7 @@ impl Grid {
} }
} }
} }
pub fn insert_column_after(&mut self, (x, y): (usize, usize)) { pub fn insert_column_after(&mut self, (x, y): (usize, usize)) {
self.insert_column_before((x + 1, y)); self.insert_column_before((x + 1, y));
} }
@@ -393,6 +397,20 @@ impl Grid {
} }
} }
pub fn range_as_indices(range: &str) -> Option<(usize, usize)> {
let v = range.split(':').collect::<Vec<&str>>();
if v.len() == 2 {
let start_col = v[0];
let end_col = v[1];
let start_idx = Grid::char_to_idx(start_col);
let end_idx = Grid::char_to_idx(end_col);
return Some((start_idx, end_idx))
}
None
}
pub fn char_to_idx(i: &str) -> usize { pub fn char_to_idx(i: &str) -> usize {
let x_idx = i let x_idx = i
.chars() .chars()
@@ -1006,6 +1024,36 @@ fn insert_col_before_3() {
assert_eq!(cell.to_string(), "=B0*B1"); assert_eq!(cell.to_string(), "=B0*B1");
} }
#[test]
fn insert_col_before_static_range() {
let mut grid = Grid::new();
grid.set_cell("A0", 2.);
grid.set_cell("A1", 2.);
grid.set_cell("B0", "=sum(A:A)".to_string());
grid.mv_cursor_to(0, 1);
grid.insert_column_before(grid.cursor());
let cell = grid.get_cell("C0").as_ref().expect("Just set it");
assert_eq!(cell.to_string(), "=sum(A:A)");
}
#[test]
fn insert_col_before_move_range() {
let mut grid = Grid::new();
grid.set_cell("B0", 2.);
grid.set_cell("B1", 2.);
grid.set_cell("A0", "=sum(B:B)".to_string());
grid.mv_cursor_to(0, 0);
grid.insert_column_after(grid.cursor());
let cell = grid.get_cell("A0").as_ref().expect("Just set it");
assert_eq!(cell.to_string(), "=sum(C:C)");
}
#[test] #[test]
fn insert_row_above_1() { fn insert_row_above_1() {
let mut grid = Grid::new(); let mut grid = Grid::new();

View File

@@ -16,24 +16,10 @@ pub struct CallbackContext<'a> {
impl<'a> CallbackContext<'a> { impl<'a> CallbackContext<'a> {
fn expand_range(&self, range: &str) -> Option<Vec<&CellType>> { fn expand_range(&self, range: &str) -> Option<Vec<&CellType>> {
let v = range.split(':').collect::<Vec<&str>>(); if let Some((start, end)) = Grid::range_as_indices(range) {
if v.len() == 2 {
let start_col = v[0];
let end_col = v[1];
let as_index = |s: &str| {
s.char_indices()
// .filter(|f| f.1 as u8 >= 97) // prevent sub with overflow errors
.map(|(idx, c)| ((c.to_ascii_lowercase() as usize).saturating_sub(97)) + (26 * idx))
.fold(0, |a, b| a + b)
};
let start_idx = as_index(start_col);
let end_idx = as_index(end_col);
let mut buf = Vec::new(); let mut buf = Vec::new();
for x in start_idx..=end_idx { for x in start..=end {
for y in 0..=self.variables.max_y_at_x(x) { for y in 0..=self.variables.max_y_at_x(x) {
if let Some(s) = self.variables.get_cell_raw(x, y) { if let Some(s) = self.variables.get_cell_raw(x, y) {
buf.push(s); buf.push(s);