From 781a1822aaf606a4182defa3dcc123350abeac22 Mon Sep 17 00:00:00 2001 From: kyoto7250 <50972773+kyoto7250@users.noreply.github.com> Date: Fri, 8 Apr 2022 11:04:49 +0900 Subject: [PATCH] adding test for expand_selected_by_horizontal_line --- src/components/table.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/table.rs b/src/components/table.rs index 80a8e37..dbea5dc 100644 --- a/src/components/table.rs +++ b/src/components/table.rs @@ -707,6 +707,32 @@ mod test { assert_eq!(component.selected_cells(), Some("b\ne".to_string())); } + #[test] + fn test_expand_selected_by_horizontal_line() { + let mut component = TableComponent::new(KeyConfig::default()); + component.headers = vec!["a", "b", "c"].iter().map(|h| h.to_string()).collect(); + component.rows = vec![ + vec!["d", "e", "f"].iter().map(|h| h.to_string()).collect(), + vec!["g", "h", "i"].iter().map(|h| h.to_string()).collect(), + ]; + + // select one line + component.selected_row.select(Some(0)); + component.expand_selected_by_horizontal_line(); + assert_eq!(component.selection_area_corner, Some((2, 0))); + assert_eq!(component.selected_cells(), Some("d,e,f".to_string())); + + // undo select horizontal line + component.expand_selected_by_horizontal_line(); + assert_eq!(component.selection_area_corner, None); + + // select two line + component.expand_selected_area_y(true); + component.expand_selected_by_horizontal_line(); + assert_eq!(component.selection_area_corner, Some((2, 1))); + assert_eq!(component.selected_cells(), Some("d,e,f\ng,h,i".to_string())); + } + #[test] fn test_is_number_column() { let mut component = TableComponent::new(KeyConfig::default());