From 69172d7abe17d56b68a97465344467d8c34482b6 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 10 May 2026 00:29:01 +0200 Subject: Fix queue display returning nothing - removed daemon pager, return full output instead. Increase pre-buffer to 100 packets. --- tests/queue.rs | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) (limited to 'tests') diff --git a/tests/queue.rs b/tests/queue.rs index bff83ca..e511612 100644 --- a/tests/queue.rs +++ b/tests/queue.rs @@ -457,3 +457,174 @@ fn test_track_no_metadata_fields() { assert!(t.artist.is_none()); assert!(t.album.is_none()); } + +// ---------- Shuffle restore ---------- + +#[test] +fn test_shuffle_all_then_none_keeps_played_tracks_in_place() { + // User's scenario: + // Queue after shuffle all: 01, 02, 03, 04(playing), 05, 06... + // Skip to track 04, then shuffle none + // Expected: played tracks (01,02,03) stay in place, current (04) stays, + // remaining tracks from original order after position + + let mut q = Queue::new(); + // Add tracks A, B, C, D, E, F (A is at index 0) + add_track(&mut q, "/music/A.mp3"); + add_track(&mut q, "/music/B.mp3"); + add_track(&mut q, "/music/C.mp3"); + add_track(&mut q, "/music/D.mp3"); + add_track(&mut q, "/music/E.mp3"); + add_track(&mut q, "/music/F.mp3"); + + // Shuffle all - should save original and shuffle + q.set_shuffle(ShuffleMode::All); + + // Simulate playing: advance position a few times + // After playing A, B, C, we're at position 2 (track C) + // Let's say shuffled order puts D at position 2 + q.next(); // position 1 (playing second track) + q.next(); // position 2 (playing third track) + q.next(); // position 3 (playing fourth track) + + let pos_before_restore = q.position(); + + // Now shuffle none - should restore + q.set_shuffle(ShuffleMode::None); + + // After restore: + // - position should be same as before + // - tracks before current position should remain in same order as when playing + // - tracks after current should be from original order that haven't been played + + let current = q.current().unwrap(); + println!("Position after restore: {}", q.position()); + println!("Current track: {:?}", current.path); + + // The position should stay the same + assert_eq!(q.position(), pos_before_restore); + + // Tracks should be: [played tracks in played order...] [current] [unplayed from original] + // Let's verify by checking that tracks before current include the ones that were played + for i in 0..q.position() { + println!("Track at {}: {:?}", i, q.track_at(i).unwrap().path); + } +} + +#[test] +fn test_shuffle_all_then_none_exact_scenario() { + // Exact scenario from user: + // Original queue: 1, 2, 3, 4, 5, 6 (position 0 = track 1) + // shuffle all -> 1, 2(playing), 4, 5, 6, 3 + // play 2 more -> 1, 2, 4, 5(playing), 6, 3 + // shuffle none -> 1, 2, 4, 5(playing), 3, 6 + + let mut q = Queue::new(); + add_track(&mut q, "/music/1.mp3"); + add_track(&mut q, "/music/2.mp3"); + add_track(&mut q, "/music/3.mp3"); + add_track(&mut q, "/music/4.mp3"); + add_track(&mut q, "/music/5.mp3"); + add_track(&mut q, "/music/6.mp3"); + + // Original order: [1, 2, 3, 4, 5, 6] + // Position 0 = track 1 + + // Shuffle all + q.set_shuffle(ShuffleMode::All); + + // Assume after shuffle and navigating to position 3 (playing track 5), + // shuffled order is [1, 2, 4, 5, 6, 3] + // We need to set this up manually since shuffle is random + + // Let's simulate by setting position to 3 (after playing 1, 2, 4, now playing 5) + // Position 3 means we've played indices 0,1,2 in shuffled order = tracks 1,2,4 + // Currently at position 3 = track 5 + + // First get the shuffled indices and manually set up a specific order + let indices: Vec = q.shuffled_indices().to_vec(); + println!("Shuffled indices: {:?}", indices); + + // Force position to 3 to simulate playing 3 tracks then current is track at pos 3 + q.set_position(3); + + let current_before = q.current().unwrap().path.clone(); + println!("Current before restore: {:?}", current_before.file_name().unwrap()); + println!("Position: {}", q.position()); + + // Now shuffle none + q.set_shuffle(ShuffleMode::None); + + println!("After restore:"); + for i in 0..q.len() { + println!(" {}: {:?}", i+1, q.track_at(i).unwrap().path.file_name().unwrap()); + } + + // After restore: + // - Position should still be 3 + // - Tracks at positions 0,1,2,3 should be the played tracks in their order (1,2,4,5) + // - Tracks 4,5 should be from original unplayed (3,6) + assert_eq!(q.position(), 3, "position should stay same"); + + let current_after = q.current().unwrap().path.clone(); + assert_eq!(current_before, current_after, "current track should stay same"); +} + +#[test] +fn test_shuffle_restore_simulation() { + // Simulate exact user scenario: + // Queue: 1,2,3,4,5,6 (original) + // shuffle all -> shuffled order e.g., [4,2,6,1,5,3] + // Navigate 4 times (play 1,2,4,5 -> position 4, now playing 5) + // Expected after shuffle none: 4,2,6,1,5,3 (played in place, unplayed from original) + + let mut q = Queue::new(); + for i in 1..=6 { + add_track(&mut q, &format!("/music/{}.mp3", i)); + } + + // Shuffle all (saves original as [1,2,3,4,5,6]) + q.set_shuffle(ShuffleMode::All); + + // Let's say shuffled order is [4, 2, 6, 1, 5, 3] + // We can force this by inspecting the indices + println!("Initial shuffled: {:?}", q.shuffled_indices()); + + // Navigate 4 times + for _ in 0..4 { + q.next(); + } + + println!("After 4 next() calls:"); + println!(" Position: {}", q.position()); + println!(" Current: {:?}", q.current().unwrap().path.file_name().unwrap()); + println!(" Tracks:"); + for i in 0..q.len() { + println!(" {}: {:?}", i, q.track_at(i).unwrap().path.file_name().unwrap()); + } + + let current_path = q.current().unwrap().path.clone(); + let pos_before = q.position(); + + // Shuffle none + q.set_shuffle(ShuffleMode::None); + + println!("After shuffle none:"); + println!(" Position: {}", q.position()); + println!(" Current: {:?}", q.current().unwrap().path.file_name().unwrap()); + println!(" Tracks:"); + for i in 0..q.len() { + println!(" {}: {:?}", i, q.track_at(i).unwrap().path.file_name().unwrap()); + } + + // Assertions + assert_eq!(q.position(), pos_before, "position should be preserved"); + assert_eq!(q.current().unwrap().path, current_path, "current track should be preserved"); + + // The key requirement: tracks before current position should remain in played order + // and tracks after should be remaining from original in original order + let pos = q.position(); + for i in 0..pos { + println!("Played track {}: {:?}", i, q.track_at(i).unwrap().path.file_name().unwrap()); + } +} -- cgit v1.2.3