From ecf3b8a4ff4206b199151a2e7044a10ddb572e39 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Mon, 5 Feb 2024 22:57:28 +0100 Subject: [PATCH] Update old unit tests --- src/tui/app/app.rs | 44 ++++++++++++------------- src/tui/app/selection.rs | 69 ++++++++++++---------------------------- src/tui/ui.rs | 10 ++++-- 3 files changed, 50 insertions(+), 73 deletions(-) diff --git a/src/tui/app/app.rs b/src/tui/app/app.rs index d3d3644..9ebf397 100644 --- a/src/tui/app/app.rs +++ b/src/tui/app/app.rs @@ -369,7 +369,7 @@ mod tests { Some(0) ); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Artist); assert_eq!(app.selection.artist.state.list.selected(), Some(1)); assert_eq!(app.selection.artist.album.state.list.selected(), Some(0)); @@ -387,7 +387,7 @@ mod tests { Some(0) ); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Album); assert_eq!(app.selection.artist.state.list.selected(), Some(1)); assert_eq!(app.selection.artist.album.state.list.selected(), Some(1)); @@ -405,7 +405,7 @@ mod tests { Some(0) ); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Track); assert_eq!(app.selection.artist.state.list.selected(), Some(1)); assert_eq!(app.selection.artist.album.state.list.selected(), Some(1)); @@ -423,7 +423,7 @@ mod tests { Some(1) ); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Track); assert_eq!(app.selection.artist.state.list.selected(), Some(1)); assert_eq!(app.selection.artist.album.state.list.selected(), Some(1)); @@ -432,7 +432,7 @@ mod tests { Some(0) ); - app.increment_selection(); + app.increment_selection(Delta::Line); app.decrement_category(); assert_eq!(app.selection.active, Category::Album); assert_eq!(app.selection.artist.state.list.selected(), Some(1)); @@ -442,7 +442,7 @@ mod tests { Some(1) ); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Album); assert_eq!(app.selection.artist.state.list.selected(), Some(1)); assert_eq!(app.selection.artist.album.state.list.selected(), Some(0)); @@ -451,7 +451,7 @@ mod tests { Some(0) ); - app.increment_selection(); + app.increment_selection(Delta::Line); app.decrement_category(); assert_eq!(app.selection.active, Category::Artist); assert_eq!(app.selection.artist.state.list.selected(), Some(1)); @@ -461,7 +461,7 @@ mod tests { Some(0) ); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Artist); assert_eq!(app.selection.artist.state.list.selected(), Some(0)); assert_eq!(app.selection.artist.album.state.list.selected(), Some(0)); @@ -471,9 +471,9 @@ mod tests { ); app.increment_category(); - app.increment_selection(); + app.increment_selection(Delta::Line); app.decrement_category(); - app.decrement_selection(); + app.decrement_selection(Delta::Line); app.decrement_category(); assert_eq!(app.selection.active, Category::Artist); assert_eq!(app.selection.artist.state.list.selected(), Some(0)); @@ -500,13 +500,13 @@ mod tests { app.increment_category(); app.increment_category(); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Track); assert_eq!(app.selection.artist.state.list.selected(), Some(0)); assert_eq!(app.selection.artist.album.state.list.selected(), Some(0)); assert_eq!(app.selection.artist.album.track.state.list.selected(), None); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Track); assert_eq!(app.selection.artist.state.list.selected(), Some(0)); assert_eq!(app.selection.artist.album.state.list.selected(), Some(0)); @@ -528,13 +528,13 @@ mod tests { app.increment_category(); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Album); assert_eq!(app.selection.artist.state.list.selected(), Some(0)); assert_eq!(app.selection.artist.album.state.list.selected(), None); assert_eq!(app.selection.artist.album.track.state.list.selected(), None); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Album); assert_eq!(app.selection.artist.state.list.selected(), Some(0)); assert_eq!(app.selection.artist.album.state.list.selected(), None); @@ -542,13 +542,13 @@ mod tests { app.increment_category(); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Track); assert_eq!(app.selection.artist.state.list.selected(), Some(0)); assert_eq!(app.selection.artist.album.state.list.selected(), None); assert_eq!(app.selection.artist.album.track.state.list.selected(), None); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Track); assert_eq!(app.selection.artist.state.list.selected(), Some(0)); assert_eq!(app.selection.artist.album.state.list.selected(), None); @@ -565,13 +565,13 @@ mod tests { assert_eq!(app.selection.artist.album.state.list.selected(), None); assert_eq!(app.selection.artist.album.track.state.list.selected(), None); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Artist); assert_eq!(app.selection.artist.state.list.selected(), None); assert_eq!(app.selection.artist.album.state.list.selected(), None); assert_eq!(app.selection.artist.album.track.state.list.selected(), None); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Artist); assert_eq!(app.selection.artist.state.list.selected(), None); assert_eq!(app.selection.artist.album.state.list.selected(), None); @@ -579,13 +579,13 @@ mod tests { app.increment_category(); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Album); assert_eq!(app.selection.artist.state.list.selected(), None); assert_eq!(app.selection.artist.album.state.list.selected(), None); assert_eq!(app.selection.artist.album.track.state.list.selected(), None); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Album); assert_eq!(app.selection.artist.state.list.selected(), None); assert_eq!(app.selection.artist.album.state.list.selected(), None); @@ -593,13 +593,13 @@ mod tests { app.increment_category(); - app.increment_selection(); + app.increment_selection(Delta::Line); assert_eq!(app.selection.active, Category::Track); assert_eq!(app.selection.artist.state.list.selected(), None); assert_eq!(app.selection.artist.album.state.list.selected(), None); assert_eq!(app.selection.artist.album.track.state.list.selected(), None); - app.decrement_selection(); + app.decrement_selection(Delta::Line); assert_eq!(app.selection.active, Category::Track); assert_eq!(app.selection.artist.state.list.selected(), None); assert_eq!(app.selection.artist.album.state.list.selected(), None); diff --git a/src/tui/app/selection.rs b/src/tui/app/selection.rs index 1b5db4f..129275f 100644 --- a/src/tui/app/selection.rs +++ b/src/tui/app/selection.rs @@ -452,17 +452,17 @@ mod tests { let mut sel = TrackSelection::initialise(tracks); assert_eq!(sel.state.list.selected(), Some(0)); - sel.decrement(tracks); + sel.decrement(tracks, Delta::Line); assert_eq!(sel.state.list.selected(), Some(0)); - sel.increment(tracks); + sel.increment(tracks, Delta::Line); assert_eq!(sel.state.list.selected(), Some(1)); - sel.decrement(tracks); + sel.decrement(tracks, Delta::Line); assert_eq!(sel.state.list.selected(), Some(0)); for _ in 0..(tracks.len() + 5) { - sel.increment(tracks); + sel.increment(tracks, Delta::Line); } assert_eq!(sel.state.list.selected(), Some(tracks.len() - 1)); @@ -474,7 +474,7 @@ mod tests { // Re-initialise out-of-bounds. let mut expected = sel.clone(); - expected.decrement(tracks); + expected.decrement(tracks, Delta::Line); let active_track = ActiveTrack::get(tracks, &sel); sel.reinitialise(&tracks[..(tracks.len() - 1)], active_track); assert_eq!(sel, expected); @@ -484,13 +484,6 @@ mod tests { let active_track = ActiveTrack::get(tracks, &sel); sel.reinitialise(&[], active_track); assert_eq!(sel, expected); - - // Artifical test case to verify upper limit. - sel.state.list.select(Some(std::usize::MAX)); - assert_eq!(sel.state.list.selected(), Some(std::usize::MAX)); - - sel.increment(&[]); - assert_eq!(sel.state.list.selected(), Some(std::usize::MAX)); } #[test] @@ -505,35 +498,35 @@ mod tests { assert_eq!(sel.state.list.selected(), Some(0)); assert_eq!(sel.track.state.list.selected(), Some(0)); - sel.increment_track(albums); + sel.increment_track(albums, Delta::Line); assert_eq!(sel.state.list.selected(), Some(0)); assert_eq!(sel.track.state.list.selected(), Some(1)); // Verify that decrement that doesn't change index does not reset track. - sel.decrement(albums); + sel.decrement(albums, Delta::Line); assert_eq!(sel.state.list.selected(), Some(0)); assert_eq!(sel.track.state.list.selected(), Some(1)); - sel.increment(albums); + sel.increment(albums, Delta::Line); assert_eq!(sel.state.list.selected(), Some(1)); assert_eq!(sel.track.state.list.selected(), Some(0)); - sel.decrement(albums); + sel.decrement(albums, Delta::Line); assert_eq!(sel.state.list.selected(), Some(0)); assert_eq!(sel.track.state.list.selected(), Some(0)); for _ in 0..(albums.len() + 5) { - sel.increment(albums); + sel.increment(albums, Delta::Line); } assert_eq!(sel.state.list.selected(), Some(albums.len() - 1)); assert_eq!(sel.track.state.list.selected(), Some(0)); - sel.increment_track(albums); + sel.increment_track(albums, Delta::Line); assert_eq!(sel.state.list.selected(), Some(albums.len() - 1)); assert_eq!(sel.track.state.list.selected(), Some(1)); // Verify that increment that doesn't change index does not reset track. - sel.increment(albums); + sel.increment(albums, Delta::Line); assert_eq!(sel.state.list.selected(), Some(albums.len() - 1)); assert_eq!(sel.track.state.list.selected(), Some(1)); @@ -545,7 +538,7 @@ mod tests { // Re-initialise out-of-bounds. let mut expected = sel.clone(); - expected.decrement(albums); + expected.decrement(albums, Delta::Line); let active_album = ActiveAlbum::get(albums, &sel); sel.reinitialise(&albums[..(albums.len() - 1)], active_album); assert_eq!(sel, expected); @@ -555,16 +548,6 @@ mod tests { let active_album = ActiveAlbum::get(albums, &sel); sel.reinitialise(&[], active_album); assert_eq!(sel, expected); - - // Artifical test case to verify upper limit. - sel.state.list.select(Some(std::usize::MAX)); - sel.track.state.list.select(Some(1)); - assert_eq!(sel.state.list.selected(), Some(std::usize::MAX)); - assert_eq!(sel.track.state.list.selected(), Some(1)); - - sel.increment(&[]); - assert_eq!(sel.state.list.selected(), Some(std::usize::MAX)); - assert_eq!(sel.track.state.list.selected(), Some(1)); } #[test] @@ -579,35 +562,35 @@ mod tests { assert_eq!(sel.state.list.selected(), Some(0)); assert_eq!(sel.album.state.list.selected(), Some(0)); - sel.increment_album(artists); + sel.increment_album(artists, Delta::Line); assert_eq!(sel.state.list.selected(), Some(0)); assert_eq!(sel.album.state.list.selected(), Some(1)); // Verify that decrement that doesn't change index does not reset album. - sel.decrement(artists); + sel.decrement(artists, Delta::Line); assert_eq!(sel.state.list.selected(), Some(0)); assert_eq!(sel.album.state.list.selected(), Some(1)); - sel.increment(artists); + sel.increment(artists, Delta::Line); assert_eq!(sel.state.list.selected(), Some(1)); assert_eq!(sel.album.state.list.selected(), Some(0)); - sel.decrement(artists); + sel.decrement(artists, Delta::Line); assert_eq!(sel.state.list.selected(), Some(0)); assert_eq!(sel.album.state.list.selected(), Some(0)); for _ in 0..(artists.len() + 5) { - sel.increment(artists); + sel.increment(artists, Delta::Line); } assert_eq!(sel.state.list.selected(), Some(artists.len() - 1)); assert_eq!(sel.album.state.list.selected(), Some(0)); - sel.increment_album(artists); + sel.increment_album(artists, Delta::Line); assert_eq!(sel.state.list.selected(), Some(artists.len() - 1)); assert_eq!(sel.album.state.list.selected(), Some(1)); // Verify that increment that doesn't change index does not reset album. - sel.increment(artists); + sel.increment(artists, Delta::Line); assert_eq!(sel.state.list.selected(), Some(artists.len() - 1)); assert_eq!(sel.album.state.list.selected(), Some(1)); @@ -619,7 +602,7 @@ mod tests { // Re-initialise out-of-bounds. let mut expected = sel.clone(); - expected.decrement(artists); + expected.decrement(artists, Delta::Line); let active_artist = ActiveArtist::get(artists, &sel); sel.reinitialise(&artists[..(artists.len() - 1)], active_artist); assert_eq!(sel, expected); @@ -629,15 +612,5 @@ mod tests { let active_artist = ActiveArtist::get(artists, &sel); sel.reinitialise(&[], active_artist); assert_eq!(sel, expected); - - // Artifical test case to verify upper limit. - sel.state.list.select(Some(std::usize::MAX)); - sel.album.state.list.select(Some(1)); - assert_eq!(sel.state.list.selected(), Some(std::usize::MAX)); - assert_eq!(sel.album.state.list.selected(), Some(1)); - - sel.increment(&[]); - assert_eq!(sel.state.list.selected(), Some(std::usize::MAX)); - assert_eq!(sel.album.state.list.selected(), Some(1)); } } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index d7b78ba..693959f 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -513,7 +513,11 @@ impl IUi for Ui { #[cfg(test)] mod tests { - use crate::tui::{app::app::AppPublic, testmod::COLLECTION, tests::terminal}; + use crate::tui::{ + app::{app::AppPublic, selection::Delta}, + testmod::COLLECTION, + tests::terminal, + }; use super::*; @@ -567,14 +571,14 @@ mod tests { // Change the track (which has a different track format). selection.increment_category(); selection.increment_category(); - selection.increment_selection(artists); + selection.increment_selection(artists, Delta::Line); draw_test_suite(artists, &mut selection); // Change the artist (which has a multi-link entry). selection.decrement_category(); selection.decrement_category(); - selection.increment_selection(artists); + selection.increment_selection(artists, Delta::Line); draw_test_suite(artists, &mut selection); }