aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/config.rs16
-rw-r--r--tests/queue.rs26
2 files changed, 38 insertions, 4 deletions
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() {
7 config_path: PathBuf::from("/test/config.toml"), 7 config_path: PathBuf::from("/test/config.toml"),
8 music_paths: vec![], 8 music_paths: vec![],
9 scan_interval: Some(3600), 9 scan_interval: Some(3600),
10 socket_path: None,
11 lastfm_api_key: None, 10 lastfm_api_key: None,
12 lastfm_api_secret: None, 11 lastfm_api_secret: None,
13 lastfm_session_key: None, 12 lastfm_session_key: None,
14 listenbrainz_token: None, 13 listenbrainz_token: None,
15 volume: None, 14 volume: None,
16 shuffle: None, 15 shuffle: None,
16 display_format: Some(String::from("$ARTIST - $TRACK")),
17 }; 17 };
18 assert_eq!(config.get("scan_interval").unwrap(), "3600"); 18 assert_eq!(config.get("scan_interval").unwrap(), "3600");
19} 19}
@@ -22,7 +22,15 @@ fn test_config_get_scan_interval() {
22fn test_config_get_not_set() { 22fn test_config_get_not_set() {
23 let config = Config { 23 let config = Config {
24 config_path: PathBuf::from("/test/config.toml"), 24 config_path: PathBuf::from("/test/config.toml"),
25 ..Default::default() 25 music_paths: vec![],
26 scan_interval: None,
27 lastfm_api_key: None,
28 lastfm_api_secret: None,
29 lastfm_session_key: None,
30 listenbrainz_token: None,
31 volume: None,
32 shuffle: None,
33 display_format: None,
26 }; 34 };
27 assert_eq!(config.get("scan_interval").unwrap(), "not set"); 35 assert_eq!(config.get("scan_interval").unwrap(), "not set");
28} 36}
@@ -33,13 +41,13 @@ fn test_config_get_volume() {
33 config_path: PathBuf::from("/test/config.toml"), 41 config_path: PathBuf::from("/test/config.toml"),
34 music_paths: vec![], 42 music_paths: vec![],
35 scan_interval: None, 43 scan_interval: None,
36 socket_path: None,
37 lastfm_api_key: None, 44 lastfm_api_key: None,
38 lastfm_api_secret: None, 45 lastfm_api_secret: None,
39 lastfm_session_key: None, 46 lastfm_session_key: None,
40 listenbrainz_token: None, 47 listenbrainz_token: None,
41 volume: Some(75), 48 volume: Some(75),
42 shuffle: None, 49 shuffle: None,
50 display_format: None,
43 }; 51 };
44 assert_eq!(config.get("volume").unwrap(), "75"); 52 assert_eq!(config.get("volume").unwrap(), "75");
45} 53}
@@ -113,13 +121,13 @@ fn test_config_unset_volume() {
113 config_path: PathBuf::from("/test/config.toml"), 121 config_path: PathBuf::from("/test/config.toml"),
114 music_paths: vec![], 122 music_paths: vec![],
115 scan_interval: None, 123 scan_interval: None,
116 socket_path: None,
117 lastfm_api_key: None, 124 lastfm_api_key: None,
118 lastfm_api_secret: None, 125 lastfm_api_secret: None,
119 lastfm_session_key: None, 126 lastfm_session_key: None,
120 listenbrainz_token: None, 127 listenbrainz_token: None,
121 volume: Some(50), 128 volume: Some(50),
122 shuffle: None, 129 shuffle: None,
130 display_format: None,
123 }; 131 };
124 config.unset("volume").unwrap(); 132 config.unset("volume").unwrap();
125 assert_eq!(config.volume, None); 133 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() {
248 assert_eq!(t.display_string(4, 10), "05. Artist - Title"); 248 assert_eq!(t.display_string(4, 10), "05. Artist - Title");
249} 249}
250 250
251#[test]
252fn test_track_format_variables() {
253 let t = track(
254 "/music/test.mp3",
255 Some("My Song"),
256 Some("John Doe"),
257 Some("Great Album"),
258 );
259 assert_eq!(t.format("$ARTIST - $TRACK"), "John Doe - My Song");
260 assert_eq!(t.format("$TRACK ($ALBUM)"), "My Song (Great Album)");
261 assert_eq!(t.format("Now playing: $ARTIST"), "Now playing: John Doe");
262}
263
264#[test]
265fn test_track_format_empty_variables() {
266 let t = track_no_meta("/music/test.mp3");
267 assert_eq!(t.format("$ARTIST - $TRACK"), " - test.mp3");
268}
269
270#[test]
271fn test_track_format_missing_variables() {
272 let t = track("/music/test.mp3", Some("My Song"), Some("John Doe"), None);
273 assert_eq!(t.format("Track: $TRACK"), "Track: My Song");
274 assert_eq!(t.format("Album: $ALBUM"), "Album: ");
275}
276
251// ---------- Shuffle ---------- 277// ---------- Shuffle ----------
252 278
253#[test] 279#[test]