Skip to content

Commit

Permalink
Update tests to sort by a column without ties (#106)
Browse files Browse the repository at this point in the history
Fixes #101
  • Loading branch information
YS-L authored Oct 15, 2024
1 parent 2927085 commit 002edeb
Showing 1 changed file with 47 additions and 41 deletions.
88 changes: 47 additions & 41 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1808,28 +1808,31 @@ mod tests {
let mut app = AppBuilder::new("tests/data/cities.csv").build().unwrap();
thread::sleep(time::Duration::from_millis(100));

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

step_and_draw(&mut app, &mut terminal, Control::ToggleSelectionType);
step_and_draw(&mut app, &mut terminal, Control::ScrollRight);
// Sort by City (no tie)
for _ in 0..8 {
step_and_draw(&mut app, &mut terminal, Control::ScrollRight);
}
step_and_draw(&mut app, &mut terminal, Control::ToggleSort);
thread::sleep(time::Duration::from_millis(200));
step_and_draw(&mut app, &mut terminal, Control::Nothing);

let actual_buffer = terminal.backend().buffer().clone();
let lines = to_lines(&actual_buffer);
let expected = vec![
"────────────────────────────────────────────────────────────────────────────────",
" LatD LatM [▴] LatS NS LonD LonM LonS EW C… ",
"─────┬──────────────────────────────────────────────────────────────────────────",
"11844 1 12 N 92 27 35 W R… ",
"49 39 2 59 N 95 40 11 W T… ",
"56 43 2 59 N 76 9 0 W S… ",
"16 40 4 11 N 80 43 12 W W… ",
"29 46 4 11 N 118 19 48 W W… ",
"─────┴──────────────────────────────────────────────────────────────────────────",
"stdin [Row 118/128, Col 1/10] ",
"────────────────────────────────────────────────────────────────────────────────────────────────────",
" LatD LatM LatS NS LonD LonM LonS EW City [▴] State ",
"─────┬─────────────────────────────────────────────────────────────────────────────────────┬────────",
"12841 9 35 N 81 14 23 W Ravenna OH │ ",
"127 40 19 48 N 75 55 48 W Reading PA │ ",
"126 40 10 48 N 122 14 23 W Red Bluff CA ",
"125 50 25 11 N 104 39 0 W Regina SA │ ",
"124 39 31 12 N 119 48 35 W Reno NV │ ",
"─────┴─────────────────────────────────────────────────────────────────────────────────────┴────────",
"stdin [Row 128/128, Col 1/10] ",
];
assert_eq!(lines, expected);

Expand All @@ -1839,16 +1842,16 @@ mod tests {
let actual_buffer = terminal.backend().buffer().clone();
let lines = to_lines(&actual_buffer);
let expected = vec![
"────────────────────────────────────────────────────────────────────────────────",
" LatD LatM [▾] LatS NS LonD LonM LonS EW C… ",
"─────┬──────────────────────────────────────────────────────────────────────────",
"59 40 59 24 N 75 11 24 W S… ",
"24 43 58 47 N 75 55 11 W W… ",
"53 27 57 0 N 82 26 59 W T… ",
"10344 57 0 N 93 5 59 W S… ",
"21 44 57 35 N 89 38 23 W W… ",
"─────┴──────────────────────────────────────────────────────────────────────────",
"stdin [Row 59/128, Col 1/10] ",
"────────────────────────────────────────────────────────────────────────────────────────────────────",
" LatD LatM LatS NS LonD LonM LonS EW City [▾] State ",
"───┬──────────────────────────────────────────────────────────────────────────────────────────┬─────",
"1 41 5 59 N 80 39 0 W Youngstown OH │ ",
"2 42 52 48 N 97 23 23 Yankton SD │ ",
"3 46 35 59 N 120 30 36 W Yakima WA │ ",
"442 16 12 N 71 48 0 W Worcester MA │ ",
"5 43 37 48 N 89 46 11 W Wisconsin Dells WI │ ",
"───┴──────────────────────────────────────────────────────────────────────────────────────────┴─────",
"stdin [Row 1/128, Col 1/10] ",
];
assert_eq!(lines, expected);
}
Expand All @@ -1862,7 +1865,10 @@ mod tests {
let mut terminal = Terminal::new(backend).unwrap();

step_and_draw(&mut app, &mut terminal, Control::ToggleSelectionType);
step_and_draw(&mut app, &mut terminal, Control::ScrollRight);
// Sort by City (no tie)
for _ in 0..8 {
step_and_draw(&mut app, &mut terminal, Control::ScrollRight);
}
step_and_draw(&mut app, &mut terminal, Control::ToggleSort);

// Toggle back to row selection mode before filtering
Expand All @@ -1886,15 +1892,15 @@ mod tests {
let lines = to_lines(&actual_buffer);
let expected = vec![
"────────────────────────────────────────────────────────────────────────────────",
" LatD LatM [▴] LatS City ",
"────┬──────────────────────────────────────────────────────────────────────────",
"9434 6 36 San Bernardino ",
"9037 20 24 San Jose ",
"88 │ 34 25 11 Santa Barbara ",
"9529 25 12 San Antonio ",
"8638 26 23 Santa Rosa ",
"────┴──────────────────────────────────────────────────────────────────────────",
"stdin [Row 94/128, Col 1/4] [Filter \"San\": 1/11] [Filter \"Lat|City\": 4/10 cols] ",
" LatD LatM LatS City [▴] ",
"────┬──────────────────────────────────────────────────────────────────────────",
"9631 27 35 San Angelo ",
"9529 25 12 San Antonio ",
"94 │ 34 6 36 San Bernardino ",
"9332 42 35 San Diego ",
"9137 46 47 San Francisco ",
"────┴──────────────────────────────────────────────────────────────────────────",
"stdin [Row 96/128, Col 1/4] [Filter \"San\": 1/11] [Filter \"Lat|City\": 4/10 cols] ",
];
assert_eq!(lines, expected);

Expand All @@ -1907,15 +1913,15 @@ mod tests {
let lines = to_lines(&actual_buffer);
let expected = vec![
"────────────────────────────────────────────────────────────────────────────────",
" LatD LatM [▾] LatS City ",
"────┬──────────────────────────────────────────────────────────────────────────",
"9137 46 47 San Francisco ",
"8933 45 35 Santa Ana ",
"9332 42 35 San Diego ",
"8735 40 48 Santa Fe ",
"9631 27 35 San Angelo ",
"────┴──────────────────────────────────────────────────────────────────────────",
"stdin [Row 91/128, Col 1/4] [Filter \"San\": -/11] [Filter \"Lat|City\": 4/10 cols] ",
" LatD LatM LatS City [▾] ",
"────┬──────────────────────────────────────────────────────────────────────────",
"8638 26 23 Santa Rosa ",
"8735 40 48 Santa Fe ",
"8834 25 11 Santa Barbara ",
"8933 45 35 Santa Ana ",
"9241 27 0 Sandusky ",
"────┴──────────────────────────────────────────────────────────────────────────",
"stdin [Row 86/128, Col 1/4] [Filter \"San\": -/11] [Filter \"Lat|City\": 4/10 cols] ",
];
assert_eq!(lines, expected);
}
Expand Down

0 comments on commit 002edeb

Please sign in to comment.