1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*
* This file is a part of RSPlayer
* Licensed under the GPL-3.0 License
* Copyright (C) 2026 Salmonik @ salmonik@tuta.io
* https://codeberg.org/salmonik/RSPlayer
*/
use rsp::database::{extract_metadata, is_audio_file};
use std::path::PathBuf;
#[test]
fn test_is_audio_file_mp3() {
let path = PathBuf::from("/music/song.mp3");
assert!(is_audio_file(&path));
}
#[test]
fn test_is_audio_file_flac() {
let path = PathBuf::from("/music/song.flac");
assert!(is_audio_file(&path));
}
#[test]
fn test_is_audio_file_ogg() {
let path = PathBuf::from("/music/song.ogg");
assert!(is_audio_file(&path));
}
#[test]
fn test_is_audio_file_m4a() {
let path = PathBuf::from("/music/song.m4a");
assert!(is_audio_file(&path));
}
#[test]
fn test_is_audio_file_wav() {
let path = PathBuf::from("/music/song.wav");
assert!(is_audio_file(&path));
}
#[test]
fn test_is_audio_file_opus() {
let path = PathBuf::from("/music/song.opus");
assert!(is_audio_file(&path));
}
#[test]
fn test_is_audio_file_uppercase() {
let path = PathBuf::from("/music/song.MP3");
assert!(is_audio_file(&path));
}
#[test]
fn test_is_audio_file_non_audio() {
let path = PathBuf::from("/music/song.txt");
assert!(!is_audio_file(&path));
}
#[test]
fn test_is_audio_file_no_extension() {
let path = PathBuf::from("/music/songfile");
assert!(!is_audio_file(&path));
}
#[test]
fn test_extract_metadata_standard_path() {
let path = PathBuf::from("/music/Artist/Album/Track.mp3");
let (artist, album, title, track_num, duration) = extract_metadata(&path);
assert_eq!(artist, "Artist");
assert_eq!(album, "Album");
assert_eq!(title, "Track");
assert_eq!(track_num, None);
assert_eq!(duration, None);
}
#[test]
fn test_extract_metadata_deep_path() {
let path = PathBuf::from("/music/Artist/Album/Disc1/Track.mp3");
let (artist, album, title, _, _) = extract_metadata(&path);
assert_eq!(artist, "Album");
assert_eq!(album, "Disc1");
assert_eq!(title, "Track");
}
#[test]
fn test_extract_metadata_no_parent() {
let path = PathBuf::from("/song.mp3");
let (artist, album, title, _, _) = extract_metadata(&path);
assert_eq!(artist, "Unknown");
assert_eq!(album, "Unknown");
assert_eq!(title, "song");
}
|