Skip to content

Commit

Permalink
add match in row subset to prevent unwarpping None type (#112)
Browse files Browse the repository at this point in the history
Co-authored-by: Yung Siang Liau <liauys@gmail.com>
  • Loading branch information
antmelon and YS-L authored Dec 1, 2024
1 parent bd7c186 commit f4e39cf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,36 @@ mod tests {
assert_eq!(lines, expected);
}

#[test]
fn test_filter_columns_irregular() {
let mut app = AppBuilder::new("tests/data/irregular.csv").build().unwrap();
till_app_ready(&app);

let backend = TestBackend::new(80, 10);
let mut terminal = Terminal::new(backend).unwrap();

step_and_draw(
&mut app,
&mut terminal,
Control::FilterColumns("COL2".into()),
);
let expected = vec![
"────────────────────────────────────────────────────────────────────────────────",
" COL2 ",
"───┬───────────┬────────────────────────────────────────────────────────────────",
"1 │ │ ",
"2 │ v2 │ ",
" │ │ ",
" │ │ ",
" │ │ ",
"───┴───────────┴────────────────────────────────────────────────────────────────",
"stdin [Row 1/2, Col 1/1] [Filter \"COL2\": 1/2 cols] ",
];
let actual_buffer = terminal.backend().buffer().clone();
let lines = to_lines(&actual_buffer);
assert_eq!(lines, expected);
}

#[test]
fn test_filter_columns_case_sensitive() {
let mut app = AppBuilder::new("tests/data/cities.csv").build().unwrap();
Expand Down
4 changes: 3 additions & 1 deletion src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ impl Row {
pub fn subset(&self, indices: &[usize]) -> Row {
let mut subfields = vec![];
for i in indices {
subfields.push(self.fields.get(*i).unwrap().clone());
if let Some(field) = self.fields.get(*i) {
subfields.push(field.clone());
}
}
Row {
record_num: self.record_num,
Expand Down

0 comments on commit f4e39cf

Please sign in to comment.