mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-22 13:00:22 -04:00
chore: cargo fmt
This commit is contained in:
parent
f3f18da254
commit
3c23142f32
126
src/book/test.rs
126
src/book/test.rs
@ -36,8 +36,15 @@ fn test_book_default() {
|
||||
#[test]
|
||||
fn test_book_insert_cell_new_row() {
|
||||
let mut book = Book::default();
|
||||
book.update_cell(&Address { sheet: 0, row: 2, col: 1 }, "1")
|
||||
.expect("failed to edit cell");
|
||||
book.update_cell(
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 1,
|
||||
},
|
||||
"1",
|
||||
)
|
||||
.expect("failed to edit cell");
|
||||
book.evaluate();
|
||||
let WorksheetDimension {
|
||||
min_row,
|
||||
@ -52,8 +59,15 @@ fn test_book_insert_cell_new_row() {
|
||||
#[test]
|
||||
fn test_book_insert_cell_new_column() {
|
||||
let mut book = Book::default();
|
||||
book.update_cell(&Address { sheet: 0, row: 1, col: 2 }, "1")
|
||||
.expect("failed to edit cell");
|
||||
book.update_cell(
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 2,
|
||||
},
|
||||
"1",
|
||||
)
|
||||
.expect("failed to edit cell");
|
||||
let WorksheetDimension {
|
||||
min_row,
|
||||
max_row,
|
||||
@ -67,14 +81,32 @@ fn test_book_insert_cell_new_column() {
|
||||
#[test]
|
||||
fn test_book_insert_rows() {
|
||||
let mut book = Book::default();
|
||||
book.update_cell(&Address { sheet: 0, row: 2, col: 2 }, "1")
|
||||
.expect("failed to edit cell");
|
||||
book.move_to(&Address { sheet: 0, row: 2, col: 2 })
|
||||
.expect("Failed to move to location");
|
||||
book.update_cell(
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2,
|
||||
},
|
||||
"1",
|
||||
)
|
||||
.expect("failed to edit cell");
|
||||
book.move_to(&Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2,
|
||||
})
|
||||
.expect("Failed to move to location");
|
||||
assert_eq!((2, 2), book.get_size().expect("Failed to get size"));
|
||||
book.insert_rows(1, 5).expect("Failed to insert rows");
|
||||
assert_eq!((7, 2), book.get_size().expect("Failed to get size"));
|
||||
assert_eq!(Address { sheet: 0, row: 7, col: 2 }, book.location);
|
||||
assert_eq!(
|
||||
Address {
|
||||
sheet: 0,
|
||||
row: 7,
|
||||
col: 2
|
||||
},
|
||||
book.location
|
||||
);
|
||||
assert_eq!(
|
||||
"1",
|
||||
book.get_current_cell_rendered()
|
||||
@ -85,14 +117,32 @@ fn test_book_insert_rows() {
|
||||
#[test]
|
||||
fn test_book_insert_columns() {
|
||||
let mut book = Book::default();
|
||||
book.update_cell(&Address { sheet: 0, row: 2, col: 2 }, "1")
|
||||
.expect("failed to edit cell");
|
||||
book.move_to(&Address { sheet: 0, row: 2, col: 2 })
|
||||
.expect("Failed to move to location");
|
||||
book.update_cell(
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2,
|
||||
},
|
||||
"1",
|
||||
)
|
||||
.expect("failed to edit cell");
|
||||
book.move_to(&Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2,
|
||||
})
|
||||
.expect("Failed to move to location");
|
||||
assert_eq!((2, 2), book.get_size().expect("Failed to get size"));
|
||||
book.insert_columns(1, 5).expect("Failed to insert rows");
|
||||
assert_eq!((2, 7), book.get_size().expect("Failed to get size"));
|
||||
assert_eq!(Address { sheet: 0, row: 2, col: 7 }, book.location);
|
||||
assert_eq!(
|
||||
Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 7
|
||||
},
|
||||
book.location
|
||||
);
|
||||
assert_eq!(
|
||||
"1",
|
||||
book.get_current_cell_rendered()
|
||||
@ -103,8 +153,15 @@ fn test_book_insert_columns() {
|
||||
#[test]
|
||||
fn test_book_col_size() {
|
||||
let mut book = Book::default();
|
||||
book.update_cell(&Address { sheet: 0, row: 2, col: 2 }, "1")
|
||||
.expect("failed to edit cell");
|
||||
book.update_cell(
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2,
|
||||
},
|
||||
"1",
|
||||
)
|
||||
.expect("failed to edit cell");
|
||||
book.set_col_size(1, 20).expect("Failed to set column size");
|
||||
assert_eq!(20, book.get_col_size(1).expect("Failed to get column size"));
|
||||
}
|
||||
@ -112,17 +169,34 @@ fn test_book_col_size() {
|
||||
#[test]
|
||||
fn test_book_get_exportable_rows() {
|
||||
let mut book = Book::default();
|
||||
book.update_cell(&Address { sheet: 0, row: 1, col: 3 }, "1-3")
|
||||
.expect("failed to edit cell");
|
||||
book.update_cell(&Address { sheet: 0, row: 3, col: 6 }, "3-6")
|
||||
.expect("failed to edit cell");
|
||||
book.update_cell(
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 3,
|
||||
},
|
||||
"1-3",
|
||||
)
|
||||
.expect("failed to edit cell");
|
||||
book.update_cell(
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 3,
|
||||
col: 6,
|
||||
},
|
||||
"3-6",
|
||||
)
|
||||
.expect("failed to edit cell");
|
||||
|
||||
let rows = book.get_export_rows().expect("Failed to get export rows");
|
||||
assert_eq!(4, rows.len());
|
||||
assert_eq!(rows, vec![
|
||||
vec!["", "" , "", "", "", "", ""],
|
||||
vec!["", "" , "", "1-3", "", "", ""],
|
||||
vec!["", "" , "", "", "", "", ""],
|
||||
vec!["", "" , "", "", "", "", "3-6"],
|
||||
]);
|
||||
assert_eq!(
|
||||
rows,
|
||||
vec![
|
||||
vec!["", "", "", "", "", "", ""],
|
||||
vec!["", "", "", "1-3", "", "", ""],
|
||||
vec!["", "", "", "", "", "", ""],
|
||||
vec!["", "", "", "", "", "", "3-6"],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -7,13 +7,16 @@ use anyhow::{anyhow, Result};
|
||||
use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
|
||||
use ironcalc::base::{expressions::types::Area, Model};
|
||||
use ratatui::{
|
||||
buffer::Buffer, layout::{Constraint, Flex, Layout}, style::{Modifier, Style}, widgets::Block
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Flex, Layout},
|
||||
style::{Modifier, Style},
|
||||
widgets::Block,
|
||||
};
|
||||
use tui_prompts::{State, Status, TextPrompt, TextState};
|
||||
use tui_textarea::{CursorMove, TextArea};
|
||||
|
||||
mod help;
|
||||
mod cmd;
|
||||
mod help;
|
||||
pub mod render;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
@ -332,16 +335,16 @@ impl<'ws> Workspace<'ws> {
|
||||
fn handle_quit_dialog(&mut self, key: event::KeyEvent) -> Result<Option<ExitCode>> {
|
||||
if key.kind == KeyEventKind::Press {
|
||||
match key.code {
|
||||
KeyCode::Esc | KeyCode::Char('n') | KeyCode::Char('N') => {
|
||||
KeyCode::Esc | KeyCode::Char('n') | KeyCode::Char('N') => {
|
||||
self.exit_quit_mode()?;
|
||||
return Ok(Some(ExitCode::SUCCESS))
|
||||
},
|
||||
return Ok(Some(ExitCode::SUCCESS));
|
||||
}
|
||||
KeyCode::Char('y') | KeyCode::Char('Y') => {
|
||||
// We have been asked to save the file first.
|
||||
self.save_file()?;
|
||||
self.exit_quit_mode()?;
|
||||
return Ok(Some(ExitCode::SUCCESS));
|
||||
},
|
||||
}
|
||||
_ => return Ok(None),
|
||||
}
|
||||
}
|
||||
@ -428,7 +431,8 @@ impl<'ws> Workspace<'ws> {
|
||||
Ok(None)
|
||||
}
|
||||
Ok(Some(Cmd::ExportCsv(path))) => {
|
||||
self.book.save_sheet_to_csv(self.book.location.sheet, path)?;
|
||||
self.book
|
||||
.save_sheet_to_csv(self.book.location.sheet, path)?;
|
||||
Ok(None)
|
||||
}
|
||||
Ok(Some(Cmd::InsertColumns(count))) => {
|
||||
@ -510,7 +514,10 @@ impl<'ws> Workspace<'ws> {
|
||||
Ok(None)
|
||||
}
|
||||
Ok(None) => {
|
||||
self.enter_dialog_mode(Markdown::from_str(&format!("Unrecognized commmand {}", cmd_text)));
|
||||
self.enter_dialog_mode(Markdown::from_str(&format!(
|
||||
"Unrecognized commmand {}",
|
||||
cmd_text
|
||||
)));
|
||||
Ok(None)
|
||||
}
|
||||
Err(msg) => {
|
||||
@ -545,18 +552,12 @@ impl<'ws> Workspace<'ws> {
|
||||
}
|
||||
KeyCode::Char('D') => {
|
||||
if let Some((start, end)) = self.state.range_select.get_range() {
|
||||
self.book.clear_cell_range_all(
|
||||
start,
|
||||
end,
|
||||
)?;
|
||||
self.book.clear_cell_range_all(start, end)?;
|
||||
}
|
||||
}
|
||||
KeyCode::Char('d') => {
|
||||
if let Some((start, end)) = self.state.range_select.get_range() {
|
||||
self.book.clear_cell_range(
|
||||
start,
|
||||
end,
|
||||
)?;
|
||||
self.book.clear_cell_range(start, end)?;
|
||||
}
|
||||
}
|
||||
KeyCode::Char('h') => {
|
||||
@ -777,7 +778,11 @@ impl<'ws> Workspace<'ws> {
|
||||
}
|
||||
KeyCode::Char('l') if key.modifiers == KeyModifiers::CONTROL => {
|
||||
self.run_with_prefix(|ws: &mut Workspace<'_>| -> Result<()> {
|
||||
let Address { sheet: _, row: _, col } = &ws.book.location;
|
||||
let Address {
|
||||
sheet: _,
|
||||
row: _,
|
||||
col,
|
||||
} = &ws.book.location;
|
||||
ws.book
|
||||
.set_col_size(*col, ws.book.get_col_size(*col)? + 1)?;
|
||||
Ok(())
|
||||
@ -785,7 +790,11 @@ impl<'ws> Workspace<'ws> {
|
||||
}
|
||||
KeyCode::Char('h') if key.modifiers == KeyModifiers::CONTROL => {
|
||||
self.run_with_prefix(|ws: &mut Workspace<'_>| -> Result<()> {
|
||||
let Address { sheet: _, row: _, col } = &ws.book.location;
|
||||
let Address {
|
||||
sheet: _,
|
||||
row: _,
|
||||
col,
|
||||
} = &ws.book.location;
|
||||
let curr_size = ws.book.get_col_size(*col)?;
|
||||
if curr_size > 1 {
|
||||
ws.book.set_col_size(*col, curr_size - 1)?;
|
||||
@ -876,21 +885,31 @@ impl<'ws> Workspace<'ws> {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
fn toggle_bool_style(&mut self, current_val: Option<bool>, path: &str, address: &Address) -> Result<(), anyhow::Error> {
|
||||
fn toggle_bool_style(
|
||||
&mut self,
|
||||
current_val: Option<bool>,
|
||||
path: &str,
|
||||
address: &Address,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let value = if let Some(b_val) = current_val {
|
||||
if b_val { "false" } else { "true" }
|
||||
if b_val {
|
||||
"false"
|
||||
} else {
|
||||
"true"
|
||||
}
|
||||
} else {
|
||||
"true"
|
||||
};
|
||||
self.book.set_cell_style(
|
||||
&[(path, value)],
|
||||
&Area {
|
||||
sheet: address.sheet,
|
||||
row: address.row as i32,
|
||||
column: address.col as i32,
|
||||
width: 1,
|
||||
height: 1,
|
||||
})?;
|
||||
sheet: address.sheet,
|
||||
row: address.row as i32,
|
||||
column: address.col as i32,
|
||||
width: 1,
|
||||
height: 1,
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -983,7 +1002,7 @@ impl<'ws> Workspace<'ws> {
|
||||
self.state.pop_modality();
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
|
||||
fn exit_command_mode(&mut self) -> Result<Option<ExitCode>> {
|
||||
let cmd = self.state.command_state.value().to_owned();
|
||||
self.state.command_state.blur();
|
||||
@ -1047,14 +1066,13 @@ impl<'ws> Workspace<'ws> {
|
||||
self.book.save_to_xlsx(path.into().as_str())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn quit_app(&mut self) -> std::result::Result<Option<ExitCode>, anyhow::Error> {
|
||||
if self.enter_quit_mode() {
|
||||
return Ok(None);
|
||||
}
|
||||
return Ok(Some(ExitCode::SUCCESS))
|
||||
return Ok(Some(ExitCode::SUCCESS));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn load_book(path: &PathBuf, locale: &str, tz: &str) -> Result<Book, anyhow::Error> {
|
||||
|
@ -42,16 +42,22 @@ impl<'w> Widget for Dialog<'w> {
|
||||
let content_width = self.content.width();
|
||||
let content_height = self.content.height();
|
||||
let vertical_margin = if ((content_height as u16) + 2) <= area.height {
|
||||
area.height.saturating_sub((content_height as u16) + 2).saturating_div(2)
|
||||
area.height
|
||||
.saturating_sub((content_height as u16) + 2)
|
||||
.saturating_div(2)
|
||||
} else {
|
||||
area.height - 2
|
||||
};
|
||||
let horizontal_margin = area.width.saturating_sub((content_width as u16) + 2).saturating_div(2);
|
||||
let horizontal_margin = area
|
||||
.width
|
||||
.saturating_sub((content_width as u16) + 2)
|
||||
.saturating_div(2);
|
||||
let [_, dialog_vertical, _] = Layout::vertical(vec![
|
||||
Constraint::Length(vertical_margin),
|
||||
Constraint::Fill(1),
|
||||
Constraint::Length(vertical_margin),
|
||||
]).areas(area);
|
||||
])
|
||||
.areas(area);
|
||||
let [_, dialog_area, _] = Layout::horizontal(vec![
|
||||
Constraint::Length(horizontal_margin),
|
||||
Constraint::Fill(1),
|
||||
|
@ -100,12 +100,18 @@ impl<'widget, 'ws: 'widget> Widget for &'widget mut Workspace<'ws> {
|
||||
Self: Sized,
|
||||
{
|
||||
if self.state.modality() == &Modality::Dialog {
|
||||
let lines = self.state.popup.as_ref().map(|md| md.get_text()).unwrap_or_else(|| Text::raw("Popup message here"));
|
||||
let lines = self
|
||||
.state
|
||||
.popup
|
||||
.as_ref()
|
||||
.map(|md| md.get_text())
|
||||
.unwrap_or_else(|| Text::raw("Popup message here"));
|
||||
let popup = dialog::Dialog::new(lines, "Help").scroll(self.state.dialog_scroll);
|
||||
popup.render(area, buf);
|
||||
} else if self.state.modality() == &Modality::Quit {
|
||||
let popup = dialog::Dialog::new(Text::raw("File is not yet saved. Save it first?"), "Quit")
|
||||
.with_bottom_title("Y/N");
|
||||
let popup =
|
||||
dialog::Dialog::new(Text::raw("File is not yet saved. Save it first?"), "Quit")
|
||||
.with_bottom_title("Y/N");
|
||||
popup.render(area, buf);
|
||||
} else {
|
||||
let outer_block = Block::bordered()
|
||||
|
@ -14,8 +14,11 @@ fn test_viewport_get_visible_columns() {
|
||||
let default_size = book.get_col_size(1).expect("Failed to get column size");
|
||||
let width = default_size * 12 / 2;
|
||||
let app_state = AppState::default();
|
||||
let viewport = Viewport::new(&book, Some(&app_state.range_select))
|
||||
.with_selected(Address { sheet: 0, row: 1, col: 17 });
|
||||
let viewport = Viewport::new(&book, Some(&app_state.range_select)).with_selected(Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 17,
|
||||
});
|
||||
let cols = viewport
|
||||
.get_visible_columns((width + 5) as u16, &mut state)
|
||||
.expect("Failed to get visible columns");
|
||||
@ -31,8 +34,11 @@ fn test_viewport_get_visible_rows() {
|
||||
);
|
||||
let height = 6;
|
||||
let app_state = AppState::default();
|
||||
let viewport = Viewport::new(&book, Some(&app_state.range_select))
|
||||
.with_selected(Address { sheet: 0, row: 17, col: 1 });
|
||||
let viewport = Viewport::new(&book, Some(&app_state.range_select)).with_selected(Address {
|
||||
sheet: 0,
|
||||
row: 17,
|
||||
col: 1,
|
||||
});
|
||||
let rows = viewport.get_visible_rows(height as u16, &mut state);
|
||||
assert_eq!(height - 1, rows.len());
|
||||
assert_eq!(
|
||||
@ -52,8 +58,11 @@ fn test_viewport_visible_columns_after_length_change() {
|
||||
let width = default_size * 12 / 2;
|
||||
{
|
||||
let app_state = AppState::default();
|
||||
let viewport = Viewport::new(&book, Some(&app_state.range_select))
|
||||
.with_selected(Address { sheet: 0, row: 1, col: 17 });
|
||||
let viewport = Viewport::new(&book, Some(&app_state.range_select)).with_selected(Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 17,
|
||||
});
|
||||
let cols = viewport
|
||||
.get_visible_columns((width + 5) as u16, &mut state)
|
||||
.expect("Failed to get visible columns");
|
||||
@ -65,8 +74,11 @@ fn test_viewport_visible_columns_after_length_change() {
|
||||
.expect("Failed to set column size");
|
||||
{
|
||||
let app_state = AppState::default();
|
||||
let viewport = Viewport::new(&book, Some(&app_state.range_select))
|
||||
.with_selected(Address { sheet: 0, row: 1, col: 1 });
|
||||
let viewport = Viewport::new(&book, Some(&app_state.range_select)).with_selected(Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1,
|
||||
});
|
||||
let cols = viewport
|
||||
.get_visible_columns((width + 5) as u16, &mut state)
|
||||
.expect("Failed to get visible columns");
|
||||
|
@ -7,8 +7,8 @@ use ratatui::{
|
||||
widgets::{Block, Cell, Row, StatefulWidget, Table, Widget},
|
||||
};
|
||||
|
||||
use crate::book;
|
||||
use super::{Address, Book, RangeSelection};
|
||||
use crate::book;
|
||||
|
||||
/// A visible column to show in our Viewport.
|
||||
#[derive(Clone, Debug)]
|
||||
@ -150,7 +150,11 @@ impl<'ws> Viewport<'ws> {
|
||||
|VisibleColumn { idx: ci, length: _ }| {
|
||||
let content = self
|
||||
.book
|
||||
.get_cell_addr_rendered(&Address { row: ri, col: *ci, sheet: self.book.location.sheet})
|
||||
.get_cell_addr_rendered(&Address {
|
||||
row: ri,
|
||||
col: *ci,
|
||||
sheet: self.book.location.sheet,
|
||||
})
|
||||
.unwrap();
|
||||
self.compute_cell_style(ri, *ci, Cell::new(Text::raw(content)))
|
||||
},
|
||||
@ -192,29 +196,27 @@ impl<'ws> Viewport<'ws> {
|
||||
mut cell: Cell<'widget>,
|
||||
) -> Cell<'widget> {
|
||||
// TODO(zaphar): Should probably create somekind of formatter abstraction.
|
||||
if let Some(style) = self
|
||||
.book
|
||||
.get_cell_style(&Address { sheet: self.book.location.sheet, row: ri, col: ci }) {
|
||||
if let Some(style) = self.book.get_cell_style(&Address {
|
||||
sheet: self.book.location.sheet,
|
||||
row: ri,
|
||||
col: ci,
|
||||
}) {
|
||||
cell = self.compute_cell_colors(&style, ri, ci, cell);
|
||||
cell = if style.font.b {
|
||||
cell.bold()
|
||||
} else { cell };
|
||||
cell = if style.font.i {
|
||||
cell.italic()
|
||||
} else { cell };
|
||||
cell = if style.font.b { cell.bold() } else { cell };
|
||||
cell = if style.font.i { cell.italic() } else { cell };
|
||||
}
|
||||
cell
|
||||
}
|
||||
|
||||
fn compute_cell_colors<'widget>(&self, style: &ironcalc::base::types::Style, ri: usize, ci: usize, mut cell: Cell<'widget>) -> Cell<'widget> {
|
||||
let bg_color = map_color(
|
||||
style.fill.bg_color.as_ref(),
|
||||
Color::Rgb(35, 33, 54),
|
||||
);
|
||||
let fg_color = map_color(
|
||||
style.fill.fg_color.as_ref(),
|
||||
Color::White,
|
||||
);
|
||||
fn compute_cell_colors<'widget>(
|
||||
&self,
|
||||
style: &ironcalc::base::types::Style,
|
||||
ri: usize,
|
||||
ci: usize,
|
||||
mut cell: Cell<'widget>,
|
||||
) -> Cell<'widget> {
|
||||
let bg_color = map_color(style.fill.bg_color.as_ref(), Color::Rgb(35, 33, 54));
|
||||
let fg_color = map_color(style.fill.fg_color.as_ref(), Color::White);
|
||||
if let Some((start, end)) = &self.range_selection.map_or(None, |r| r.get_range()) {
|
||||
if ri >= start.row && ri <= end.row && ci >= start.col && ci <= end.col {
|
||||
// This is a selected range
|
||||
|
209
src/ui/test.rs
209
src/ui/test.rs
@ -554,9 +554,7 @@ fn test_range_copy() {
|
||||
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
|
||||
|
||||
let address = Address::default();
|
||||
ws.book
|
||||
.move_to(&address)
|
||||
.expect("Failed to move to row");
|
||||
ws.book.move_to(&address).expect("Failed to move to row");
|
||||
let original_loc = ws.book.location.clone();
|
||||
script()
|
||||
.ctrl('r')
|
||||
@ -576,7 +574,11 @@ fn test_range_copy() {
|
||||
.run(&mut ws)
|
||||
.expect("Failed to handle key sequence");
|
||||
assert_eq!(
|
||||
Some(Address { sheet: 0, row: 1, col: 2 }),
|
||||
Some(Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 2
|
||||
}),
|
||||
ws.state.range_select.start
|
||||
);
|
||||
|
||||
@ -588,18 +590,40 @@ fn test_range_copy() {
|
||||
|
||||
assert!(ws.state.range_select.original_location.is_none());
|
||||
assert_eq!(
|
||||
Some(Address { sheet: 0, row: 1, col: 2 }),
|
||||
Some(Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 2
|
||||
}),
|
||||
ws.state.range_select.start
|
||||
);
|
||||
assert_eq!(Some(Address { sheet: 0, row: 2, col: 2 }), ws.state.range_select.end);
|
||||
assert_eq!(
|
||||
Some(Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2
|
||||
}),
|
||||
ws.state.range_select.end
|
||||
);
|
||||
assert_eq!(original_loc, ws.book.location);
|
||||
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
|
||||
|
||||
ws.book
|
||||
.move_to(&Address { sheet: 0, row: 5, col: 5 })
|
||||
.move_to(&Address {
|
||||
sheet: 0,
|
||||
row: 5,
|
||||
col: 5,
|
||||
})
|
||||
.expect("Failed to move to row");
|
||||
let original_loc_2 = ws.book.location.clone();
|
||||
assert_eq!(Address { sheet: 0, row: 5, col: 5 }, original_loc_2);
|
||||
assert_eq!(
|
||||
Address {
|
||||
sheet: 0,
|
||||
row: 5,
|
||||
col: 5
|
||||
},
|
||||
original_loc_2
|
||||
);
|
||||
|
||||
script()
|
||||
.char('v')
|
||||
@ -619,7 +643,11 @@ fn test_range_copy() {
|
||||
.run(&mut ws)
|
||||
.expect("Failed to handle key sequence");
|
||||
assert_eq!(
|
||||
Some(Address { sheet: 0, row: 5, col: 5 }),
|
||||
Some(Address {
|
||||
sheet: 0,
|
||||
row: 5,
|
||||
col: 5
|
||||
}),
|
||||
ws.state.range_select.start
|
||||
);
|
||||
|
||||
@ -631,11 +659,29 @@ fn test_range_copy() {
|
||||
|
||||
assert!(ws.state.range_select.original_location.is_none());
|
||||
assert_eq!(
|
||||
Some(Address { sheet: 0, row: 5, col: 5 }),
|
||||
Some(Address {
|
||||
sheet: 0,
|
||||
row: 5,
|
||||
col: 5
|
||||
}),
|
||||
ws.state.range_select.start
|
||||
);
|
||||
assert_eq!(Some(Address { sheet: 0, row: 5, col: 4 }), ws.state.range_select.end);
|
||||
assert_eq!(Address { sheet: 0, row: 4, col: 5 }, ws.book.location);
|
||||
assert_eq!(
|
||||
Some(Address {
|
||||
sheet: 0,
|
||||
row: 5,
|
||||
col: 4
|
||||
}),
|
||||
ws.state.range_select.end
|
||||
);
|
||||
assert_eq!(
|
||||
Address {
|
||||
sheet: 0,
|
||||
row: 4,
|
||||
col: 5
|
||||
},
|
||||
ws.book.location
|
||||
);
|
||||
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
|
||||
}
|
||||
|
||||
@ -664,14 +710,28 @@ fn test_gg_movement() {
|
||||
.char('j')
|
||||
.run(&mut ws)
|
||||
.expect("failed to handle event sequence");
|
||||
assert_eq!(ws.book.location, Address { sheet: 0, row: 3, col: 1 });
|
||||
assert_eq!(
|
||||
ws.book.location,
|
||||
Address {
|
||||
sheet: 0,
|
||||
row: 3,
|
||||
col: 1
|
||||
}
|
||||
);
|
||||
script()
|
||||
.char('l')
|
||||
.char('g')
|
||||
.char('g')
|
||||
.run(&mut ws)
|
||||
.expect("failed to handle event sequence");
|
||||
assert_eq!(ws.book.location, Address { sheet: 0, row: 1, col: 2 });
|
||||
assert_eq!(
|
||||
ws.book.location,
|
||||
Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 2
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -684,14 +744,28 @@ fn test_h_j_k_l_movement() {
|
||||
.char('l')
|
||||
.run(&mut ws)
|
||||
.expect("failed to handle event sequence");
|
||||
assert_eq!(ws.book.location, Address { sheet: 0, row: 3, col: 2 });
|
||||
assert_eq!(
|
||||
ws.book.location,
|
||||
Address {
|
||||
sheet: 0,
|
||||
row: 3,
|
||||
col: 2
|
||||
}
|
||||
);
|
||||
script()
|
||||
.char('h')
|
||||
.char('2')
|
||||
.char('k')
|
||||
.run(&mut ws)
|
||||
.expect("failed to handle event sequence");
|
||||
assert_eq!(ws.book.location, Address { sheet: 0, row: 1, col: 1 });
|
||||
assert_eq!(
|
||||
ws.book.location,
|
||||
Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! assert_copy_paste {
|
||||
@ -930,8 +1004,16 @@ fn test_command_mode_enter() {
|
||||
fn test_edit_mode_paste() {
|
||||
let mut ws = new_workspace();
|
||||
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
|
||||
ws.state.range_select.start = Some(Address { sheet: 0, row: 1, col: 1 });
|
||||
ws.state.range_select.end = Some(Address { sheet: 0, row: 2, col: 2 });
|
||||
ws.state.range_select.start = Some(Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1,
|
||||
});
|
||||
ws.state.range_select.end = Some(Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2,
|
||||
});
|
||||
script()
|
||||
.char('e')
|
||||
.ctrl('p')
|
||||
@ -979,8 +1061,16 @@ macro_rules! assert_range_clear {
|
||||
($script : expr) => {{
|
||||
let mut ws = new_workspace();
|
||||
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
|
||||
let first_corner = Address { sheet: 0, row: 1, col: 1 };
|
||||
let second_corner = Address { sheet: 0, row: 2, col: 2 };
|
||||
let first_corner = Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1,
|
||||
};
|
||||
let second_corner = Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2,
|
||||
};
|
||||
ws.book
|
||||
.update_cell(&first_corner, "foo")
|
||||
.expect("Failed to update cell");
|
||||
@ -1050,7 +1140,14 @@ fn test_range_select_movement() {
|
||||
.char('k')
|
||||
.run(&mut ws)
|
||||
.expect("failed to run script");
|
||||
assert_eq!(&Address { sheet: 0, row: 3, col: 3 }, &ws.book.location);
|
||||
assert_eq!(
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 3,
|
||||
col: 3
|
||||
},
|
||||
&ws.book.location
|
||||
);
|
||||
script()
|
||||
.ctrl('n')
|
||||
.run(&mut ws)
|
||||
@ -1071,8 +1168,16 @@ fn test_range_select_clear_lower_d() {
|
||||
macro_rules! assert_range_copy {
|
||||
($script: expr) => {{
|
||||
let mut ws = new_workspace();
|
||||
let top_left_addr = Address { sheet: 0, row: 2, col: 2 };
|
||||
let bot_right_addr = Address { sheet: 0, row: 4, col: 4 };
|
||||
let top_left_addr = Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 2,
|
||||
};
|
||||
let bot_right_addr = Address {
|
||||
sheet: 0,
|
||||
row: 4,
|
||||
col: 4,
|
||||
};
|
||||
ws.book
|
||||
.update_cell(&top_left_addr, "top_left")
|
||||
.expect("Failed to update top left");
|
||||
@ -1111,7 +1216,11 @@ macro_rules! assert_range_copy {
|
||||
.expect("Didn't find a start of range")
|
||||
);
|
||||
assert_eq!(
|
||||
&Address { sheet: 0, row: 1, col: 1 },
|
||||
&Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1
|
||||
},
|
||||
ws.state
|
||||
.range_select
|
||||
.original_location
|
||||
@ -1179,7 +1288,11 @@ fn test_extend_to_range() {
|
||||
.expect("Unable to run script");
|
||||
let extended_cell = ws
|
||||
.book
|
||||
.get_cell_addr_contents(&Address { sheet: 0, row: 2, col: 1 })
|
||||
.get_cell_addr_contents(&Address {
|
||||
sheet: 0,
|
||||
row: 2,
|
||||
col: 1,
|
||||
})
|
||||
.expect("Failed to get cell contents");
|
||||
assert_eq!("=B2+1".to_string(), extended_cell);
|
||||
}
|
||||
@ -1199,7 +1312,11 @@ fn test_color_cells() {
|
||||
for ci in 1..=3 {
|
||||
let style = ws
|
||||
.book
|
||||
.get_cell_style(&Address { sheet: ws.book.location.sheet, row: ri, col: ci })
|
||||
.get_cell_style(&Address {
|
||||
sheet: ws.book.location.sheet,
|
||||
row: ri,
|
||||
col: ci,
|
||||
})
|
||||
.expect("failed to get style");
|
||||
assert_eq!(
|
||||
"#800000",
|
||||
@ -1225,7 +1342,11 @@ fn test_color_row() {
|
||||
for ci in [1, book::LAST_COLUMN] {
|
||||
let style = ws
|
||||
.book
|
||||
.get_cell_style(&Address { sheet: ws.book.location.sheet, row: 1, col: ci as usize })
|
||||
.get_cell_style(&Address {
|
||||
sheet: ws.book.location.sheet,
|
||||
row: 1,
|
||||
col: ci as usize,
|
||||
})
|
||||
.expect("failed to get style");
|
||||
assert_eq!(
|
||||
"#800000",
|
||||
@ -1250,7 +1371,11 @@ fn test_color_col() {
|
||||
for ri in [1, book::LAST_ROW] {
|
||||
let style = ws
|
||||
.book
|
||||
.get_cell_style(&Address { sheet: ws.book.location.sheet, row: ri as usize, col: 1 })
|
||||
.get_cell_style(&Address {
|
||||
sheet: ws.book.location.sheet,
|
||||
row: ri as usize,
|
||||
col: 1,
|
||||
})
|
||||
.expect("failed to get style");
|
||||
assert_eq!(
|
||||
"#800000",
|
||||
@ -1268,7 +1393,11 @@ fn test_bold_text() {
|
||||
let mut ws = new_workspace();
|
||||
let before_style = ws
|
||||
.book
|
||||
.get_cell_style(&Address { sheet: 0, row: 1, col: 1 })
|
||||
.get_cell_style(&Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1,
|
||||
})
|
||||
.expect("Failed to get style");
|
||||
assert!(!before_style.font.b);
|
||||
script()
|
||||
@ -1277,7 +1406,11 @@ fn test_bold_text() {
|
||||
.expect("Unable to run script");
|
||||
let style = ws
|
||||
.book
|
||||
.get_cell_style(&Address { sheet: 0, row: 1, col: 1 })
|
||||
.get_cell_style(&Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1,
|
||||
})
|
||||
.expect("Failed to get style");
|
||||
assert!(style.font.b);
|
||||
script()
|
||||
@ -1292,7 +1425,11 @@ fn test_italic_text() {
|
||||
let mut ws = new_workspace();
|
||||
let before_style = ws
|
||||
.book
|
||||
.get_cell_style(&Address { sheet: 0, row: 1, col: 1 })
|
||||
.get_cell_style(&Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1,
|
||||
})
|
||||
.expect("Failed to get style");
|
||||
assert!(!before_style.font.i);
|
||||
script()
|
||||
@ -1301,7 +1438,11 @@ fn test_italic_text() {
|
||||
.expect("Unable to run script");
|
||||
let style = ws
|
||||
.book
|
||||
.get_cell_style(&Address { sheet: 0, row: 1, col: 1 })
|
||||
.get_cell_style(&Address {
|
||||
sheet: 0,
|
||||
row: 1,
|
||||
col: 1,
|
||||
})
|
||||
.expect("Failed to get style");
|
||||
assert!(style.font.i);
|
||||
script()
|
||||
@ -1331,7 +1472,7 @@ fn test_quit_dialog() {
|
||||
.run(&mut ws)
|
||||
.expect("Failed to run input script");
|
||||
assert!(result.is_some());
|
||||
|
||||
|
||||
script()
|
||||
.chars("efoo")
|
||||
.enter()
|
||||
@ -1344,7 +1485,7 @@ fn test_quit_dialog() {
|
||||
.expect("Failed to run input script");
|
||||
assert!(!result.is_some());
|
||||
assert_eq!(ws.state.modality(), &Modality::Quit);
|
||||
|
||||
|
||||
script()
|
||||
.char('n')
|
||||
.run(&mut ws)
|
||||
|
Loading…
x
Reference in New Issue
Block a user