From 455ec54613230f4004a24f8d2798fb0084e00cb4 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 11 May 2026 16:25:49 +0200 Subject: Add display_format config, fix restart command, clean up config code - Add display_format option with get/set/list/unset for customizing track display - Add Track::format() supporting $ARTIST, $ALBUM, $TRACK variables - Update queue, status, notifications to use display_format - Fix restart command using wrong subcommand 'start' -> 'start-daemon' - Remove socket_path from config (now computed at runtime from XDG_RUNTIME_DIR) - Consolidate duplicate save() and save_all() into single save() - Fix redundant .clone().clone() in config.rs - Add todo item for caching config in daemon hot paths --- tests/config.rs | 16 ++++++++++++---- tests/queue.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/config.rs b/tests/config.rs index 70c5034..1702db9 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -7,13 +7,13 @@ fn test_config_get_scan_interval() { config_path: PathBuf::from("/test/config.toml"), music_paths: vec![], scan_interval: Some(3600), - socket_path: None, lastfm_api_key: None, lastfm_api_secret: None, lastfm_session_key: None, listenbrainz_token: None, volume: None, shuffle: None, + display_format: Some(String::from("$ARTIST - $TRACK")), }; assert_eq!(config.get("scan_interval").unwrap(), "3600"); } @@ -22,7 +22,15 @@ fn test_config_get_scan_interval() { fn test_config_get_not_set() { let config = Config { config_path: PathBuf::from("/test/config.toml"), - ..Default::default() + music_paths: vec![], + scan_interval: None, + lastfm_api_key: None, + lastfm_api_secret: None, + lastfm_session_key: None, + listenbrainz_token: None, + volume: None, + shuffle: None, + display_format: None, }; assert_eq!(config.get("scan_interval").unwrap(), "not set"); } @@ -33,13 +41,13 @@ fn test_config_get_volume() { config_path: PathBuf::from("/test/config.toml"), music_paths: vec![], scan_interval: None, - socket_path: None, lastfm_api_key: None, lastfm_api_secret: None, lastfm_session_key: None, listenbrainz_token: None, volume: Some(75), shuffle: None, + display_format: None, }; assert_eq!(config.get("volume").unwrap(), "75"); } @@ -113,13 +121,13 @@ fn test_config_unset_volume() { config_path: PathBuf::from("/test/config.toml"), music_paths: vec![], scan_interval: None, - socket_path: None, lastfm_api_key: None, lastfm_api_secret: None, lastfm_session_key: None, listenbrainz_token: None, volume: Some(50), shuffle: None, + display_format: None, }; config.unset("volume").unwrap(); assert_eq!(config.volume, None); diff --git a/tests/queue.rs b/tests/queue.rs index 438fa23..a73c312 100644 --- a/tests/queue.rs +++ b/tests/queue.rs @@ -248,6 +248,32 @@ fn test_track_display_index_offset() { assert_eq!(t.display_string(4, 10), "05. Artist - Title"); } +#[test] +fn test_track_format_variables() { + let t = track( + "/music/test.mp3", + Some("My Song"), + Some("John Doe"), + Some("Great Album"), + ); + assert_eq!(t.format("$ARTIST - $TRACK"), "John Doe - My Song"); + assert_eq!(t.format("$TRACK ($ALBUM)"), "My Song (Great Album)"); + assert_eq!(t.format("Now playing: $ARTIST"), "Now playing: John Doe"); +} + +#[test] +fn test_track_format_empty_variables() { + let t = track_no_meta("/music/test.mp3"); + assert_eq!(t.format("$ARTIST - $TRACK"), " - test.mp3"); +} + +#[test] +fn test_track_format_missing_variables() { + let t = track("/music/test.mp3", Some("My Song"), Some("John Doe"), None); + assert_eq!(t.format("Track: $TRACK"), "Track: My Song"); + assert_eq!(t.format("Album: $ALBUM"), "Album: "); +} + // ---------- Shuffle ---------- #[test] -- cgit v1.2.3