diff --git a/src/client/channel.rs b/src/client/channel.rs index 89334d4..e9b7106 100644 --- a/src/client/channel.rs +++ b/src/client/channel.rs @@ -496,6 +496,7 @@ mod tests { model::{paginator::Paginator, Channel, ChannelInfo, PlaylistItem, VideoItem}, param::Language, serializer::MapResult, + util::tests::TESTFILES, }; #[rstest] @@ -510,7 +511,7 @@ mod tests { #[case::shorts("shorts", "UCh8gHdtzO2tXd593_bjErWg")] #[case::livestreams("livestreams", "UC2DjFE7Xf11URZqWBigcVOQ")] fn map_channel_videos(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "channel" / format!("channel_{name}.json")); + let json_path = path!(*TESTFILES / "channel" / format!("channel_{name}.json")); let json_file = File::open(json_path).unwrap(); let channel: response::Channel = @@ -535,9 +536,9 @@ mod tests { } } - #[test] + #[rstest] fn map_channel_playlists() { - let json_path = path!("testfiles" / "channel" / "channel_playlists.json"); + let json_path = path!(*TESTFILES / "channel" / "channel_playlists.json"); let json_file = File::open(json_path).unwrap(); let channel: response::Channel = @@ -554,9 +555,9 @@ mod tests { insta::assert_ron_snapshot!("map_channel_playlists", map_res.c); } - #[test] + #[rstest] fn map_channel_info() { - let json_path = path!("testfiles" / "channel" / "channel_info.json"); + let json_path = path!(*TESTFILES / "channel" / "channel_info.json"); let json_file = File::open(json_path).unwrap(); let channel: response::Channel = diff --git a/src/client/channel_rss.rs b/src/client/channel_rss.rs index c98dac5..d28f81e 100644 --- a/src/client/channel_rss.rs +++ b/src/client/channel_rss.rs @@ -68,7 +68,7 @@ impl RustyPipeQuery { mod tests { use std::{fs::File, io::BufReader}; - use crate::{client::response, model::ChannelRss}; + use crate::{client::response, model::ChannelRss, util::tests::TESTFILES}; use path_macro::path; use rstest::rstest; @@ -78,7 +78,7 @@ mod tests { #[case::no_likes("no_likes")] #[case::no_channel_id("no_channel_id")] fn map_channel_rss(#[case] name: &str) { - let xml_path = path!("testfiles" / "channel_rss" / format!("{}.xml", name)); + let xml_path = path!(*TESTFILES / "channel_rss" / format!("{}.xml", name)); let xml_file = File::open(xml_path).unwrap(); let feed: response::ChannelRss = diff --git a/src/client/music_artist.rs b/src/client/music_artist.rs index 0311eb0..ff2aa61 100644 --- a/src/client/music_artist.rs +++ b/src/client/music_artist.rs @@ -367,7 +367,7 @@ mod tests { use path_macro::path; use rstest::rstest; - use crate::param::Language; + use crate::{param::Language, util::tests::TESTFILES}; use super::*; @@ -378,12 +378,12 @@ mod tests { #[case::no_artist("no_artist", "UCh8gHdtzO2tXd593_bjErWg")] #[case::only_more_singles("only_more_singles", "UC0aXrjVxG5pZr99v77wZdPQ")] fn map_music_artist(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "music_artist" / format!("artist_{name}.json")); + let json_path = path!(*TESTFILES / "music_artist" / format!("artist_{name}.json")); let json_file = File::open(json_path).unwrap(); let mut album_page_paths = Vec::new(); for i in 1..=2 { - let json_path = path!("testfiles" / "music_artist" / format!("artist_{name}_{i}.json")); + let json_path = path!(*TESTFILES / "music_artist" / format!("artist_{name}_{i}.json")); if !json_path.exists() { break; } @@ -423,7 +423,7 @@ mod tests { #[test] fn map_music_artist_no_cont() { - let json_path = path!("testfiles" / "music_artist" / "artist_default.json"); + let json_path = path!(*TESTFILES / "music_artist" / "artist_default.json"); let json_file = File::open(json_path).unwrap(); let artist: response::MusicArtist = @@ -442,7 +442,7 @@ mod tests { #[test] fn map_music_artist_secondary_channel() { - let json_path = path!("testfiles" / "music_artist" / "artist_secondary_channel.json"); + let json_path = path!(*TESTFILES / "music_artist" / "artist_secondary_channel.json"); let json_file = File::open(json_path).unwrap(); let artist: response::MusicArtist = diff --git a/src/client/music_details.rs b/src/client/music_details.rs index e40c4d8..850e93f 100644 --- a/src/client/music_details.rs +++ b/src/client/music_details.rs @@ -395,13 +395,13 @@ mod tests { use rstest::rstest; use super::*; - use crate::{model, param::Language}; + use crate::{model, param::Language, util::tests::TESTFILES}; #[rstest] #[case::mv("mv", "ZeerrnuLi5E")] #[case::track("track", "7nigXQS1Xb0")] fn map_music_details(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "music_details" / format!("details_{name}.json")); + let json_path = path!(*TESTFILES / "music_details" / format!("details_{name}.json")); let json_file = File::open(json_path).unwrap(); let details: response::MusicDetails = @@ -421,7 +421,7 @@ mod tests { #[case::mv("mv", "RDAMVMZeerrnuLi5E")] #[case::track("track", "RDAMVM7nigXQS1Xb0")] fn map_music_radio(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "music_details" / format!("radio_{name}.json")); + let json_path = path!(*TESTFILES / "music_details" / format!("radio_{name}.json")); let json_file = File::open(json_path).unwrap(); let radio: response::MusicDetails = @@ -439,7 +439,7 @@ mod tests { #[test] fn map_lyrics() { - let json_path = path!("testfiles" / "music_details" / "lyrics.json"); + let json_path = path!(*TESTFILES / "music_details" / "lyrics.json"); let json_file = File::open(json_path).unwrap(); let lyrics: response::MusicLyrics = @@ -456,7 +456,7 @@ mod tests { #[test] fn map_related() { - let json_path = path!("testfiles" / "music_details" / "related.json"); + let json_path = path!(*TESTFILES / "music_details" / "related.json"); let json_file = File::open(json_path).unwrap(); let lyrics: response::MusicRelated = diff --git a/src/client/music_genres.rs b/src/client/music_genres.rs index 380b4b0..d6d31e9 100644 --- a/src/client/music_genres.rs +++ b/src/client/music_genres.rs @@ -202,11 +202,11 @@ mod tests { use rstest::rstest; use super::*; - use crate::{model, param::Language}; + use crate::{model, param::Language, util::tests::TESTFILES}; #[test] fn map_music_genres() { - let json_path = path!("testfiles" / "music_genres" / "genres.json"); + let json_path = path!(*TESTFILES / "music_genres" / "genres.json"); let json_file = File::open(json_path).unwrap(); let playlist: response::MusicGenres = @@ -226,7 +226,7 @@ mod tests { #[case::default("default", "ggMPOg1uX1lMbVZmbzl6NlJ3")] #[case::mood("mood", "ggMPOg1uX1JOQWZFeDByc2Jm")] fn map_music_genre(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "music_genres" / format!("genre_{name}.json")); + let json_path = path!(*TESTFILES / "music_genres" / format!("genre_{name}.json")); let json_file = File::open(json_path).unwrap(); let playlist: response::MusicGenre = diff --git a/src/client/music_new.rs b/src/client/music_new.rs index de20415..16650d8 100644 --- a/src/client/music_new.rs +++ b/src/client/music_new.rs @@ -85,12 +85,12 @@ mod tests { use rstest::rstest; use super::*; - use crate::{param::Language, serializer::MapResult}; + use crate::{param::Language, serializer::MapResult, util::tests::TESTFILES}; #[rstest] #[case::default("default")] fn map_music_new_albums(#[case] name: &str) { - let json_path = path!("testfiles" / "music_new" / format!("albums_{name}.json")); + let json_path = path!(*TESTFILES / "music_new" / format!("albums_{name}.json")); let json_file = File::open(json_path).unwrap(); let new_albums: response::MusicNew = @@ -109,7 +109,7 @@ mod tests { #[rstest] #[case::default("default")] fn map_music_new_videos(#[case] name: &str) { - let json_path = path!("testfiles" / "music_new" / format!("videos_{name}.json")); + let json_path = path!(*TESTFILES / "music_new" / format!("videos_{name}.json")); let json_file = File::open(json_path).unwrap(); let new_albums: response::MusicNew = diff --git a/src/client/music_playlist.rs b/src/client/music_playlist.rs index 016b023..20c9fb5 100644 --- a/src/client/music_playlist.rs +++ b/src/client/music_playlist.rs @@ -393,14 +393,14 @@ mod tests { use rstest::rstest; use super::*; - use crate::{model, param::Language}; + use crate::{model, param::Language, util::tests::TESTFILES}; #[rstest] #[case::short("short", "RDCLAK5uy_kFQXdnqMaQCVx2wpUM4ZfbsGCDibZtkJk")] #[case::long("long", "PL5dDx681T4bR7ZF1IuWzOv1omlRbE7PiJ")] #[case::nomusic("nomusic", "PL1J-6JOckZtE_P9Xx8D3b2O6w0idhuKBe")] fn map_music_playlist(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "music_playlist" / format!("playlist_{name}.json")); + let json_path = path!(*TESTFILES / "music_playlist" / format!("playlist_{name}.json")); let json_file = File::open(json_path).unwrap(); let playlist: response::MusicPlaylist = @@ -425,7 +425,7 @@ mod tests { #[case::description("description", "MPREb_PiyfuVl6aYd")] #[case::unavailable("unavailable", "MPREb_AzuWg8qAVVl")] fn map_music_album(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "music_playlist" / format!("album_{name}.json")); + let json_path = path!(*TESTFILES / "music_playlist" / format!("album_{name}.json")); let json_file = File::open(json_path).unwrap(); let playlist: response::MusicPlaylist = diff --git a/src/client/music_search.rs b/src/client/music_search.rs index 833152b..5e6f712 100644 --- a/src/client/music_search.rs +++ b/src/client/music_search.rs @@ -387,6 +387,7 @@ mod tests { }, param::Language, serializer::MapResult, + util::tests::TESTFILES, }; #[rstest] @@ -394,7 +395,7 @@ mod tests { #[case::typo("typo")] #[case::radio("radio")] fn map_music_search_main(#[case] name: &str) { - let json_path = path!("testfiles" / "music_search" / format!("main_{name}.json")); + let json_path = path!(*TESTFILES / "music_search" / format!("main_{name}.json")); let json_file = File::open(json_path).unwrap(); let search: response::MusicSearch = @@ -417,7 +418,7 @@ mod tests { #[case::videos("videos")] #[case::no_artist_link("no_artist_link")] fn map_music_search_tracks(#[case] name: &str) { - let json_path = path!("testfiles" / "music_search" / format!("tracks_{name}.json")); + let json_path = path!(*TESTFILES / "music_search" / format!("tracks_{name}.json")); let json_file = File::open(json_path).unwrap(); let search: response::MusicSearch = @@ -436,7 +437,7 @@ mod tests { #[test] fn map_music_search_albums() { - let json_path = path!("testfiles" / "music_search" / "albums.json"); + let json_path = path!(*TESTFILES / "music_search" / "albums.json"); let json_file = File::open(json_path).unwrap(); let search: response::MusicSearch = @@ -455,7 +456,7 @@ mod tests { #[test] fn map_music_search_artists() { - let json_path = path!("testfiles" / "music_search" / "artists.json"); + let json_path = path!(*TESTFILES / "music_search" / "artists.json"); let json_file = File::open(json_path).unwrap(); let search: response::MusicSearch = @@ -476,7 +477,7 @@ mod tests { #[case::ytm("ytm")] #[case::community("community")] fn map_music_search_playlists(#[case] name: &str) { - let json_path = path!("testfiles" / "music_search" / format!("playlists_{name}.json")); + let json_path = path!(*TESTFILES / "music_search" / format!("playlists_{name}.json")); let json_file = File::open(json_path).unwrap(); let search: response::MusicSearch = @@ -497,7 +498,7 @@ mod tests { #[case::default("default")] #[case::empty("empty")] fn map_music_search_suggestion(#[case] name: &str) { - let json_path = path!("testfiles" / "music_search" / format!("suggestion_{name}.json")); + let json_path = path!(*TESTFILES / "music_search" / format!("suggestion_{name}.json")); let json_file = File::open(json_path).unwrap(); let suggestion: response::MusicSearchSuggestion = diff --git a/src/client/pagination.rs b/src/client/pagination.rs index 2d87b51..89ccadd 100644 --- a/src/client/pagination.rs +++ b/src/client/pagination.rs @@ -344,15 +344,18 @@ mod tests { use rstest::rstest; use super::*; - use crate::model::{MusicPlaylistItem, PlaylistItem, TrackItem}; - use crate::param::Language; + use crate::{ + model::{MusicPlaylistItem, PlaylistItem, TrackItem}, + param::Language, + util::tests::TESTFILES, + }; #[rstest] #[case("search", path!("search" / "cont.json"))] #[case("startpage", path!("trends" / "startpage_cont.json"))] #[case("recommendations", path!("video_details" / "recommendations.json"))] fn map_continuation_items(#[case] name: &str, #[case] path: PathBuf) { - let json_path = path!("testfiles" / path); + let json_path = path!(*TESTFILES / path); let json_file = File::open(json_path).unwrap(); let items: response::Continuation = @@ -373,7 +376,7 @@ mod tests { #[rstest] #[case("channel_playlists", path!("channel" / "channel_playlists_cont.json"))] fn map_continuation_playlists(#[case] name: &str, #[case] path: PathBuf) { - let json_path = path!("testfiles" / path); + let json_path = path!(*TESTFILES / path); let json_file = File::open(json_path).unwrap(); let items: response::Continuation = @@ -396,7 +399,7 @@ mod tests { #[case("search_tracks", path!("music_search" / "tracks_cont.json"))] #[case("radio_tracks", path!("music_details" / "radio_cont.json"))] fn map_continuation_tracks(#[case] name: &str, #[case] path: PathBuf) { - let json_path = path!("testfiles" / path); + let json_path = path!(*TESTFILES / path); let json_file = File::open(json_path).unwrap(); let items: response::MusicContinuation = @@ -417,7 +420,7 @@ mod tests { #[rstest] #[case("playlist_related", path!("music_playlist" / "playlist_related.json"))] fn map_continuation_music_playlists(#[case] name: &str, #[case] path: PathBuf) { - let json_path = path!("testfiles" / path); + let json_path = path!(*TESTFILES / path); let json_file = File::open(json_path).unwrap(); let items: response::MusicContinuation = diff --git a/src/client/player.rs b/src/client/player.rs index f4131a5..a9358f7 100644 --- a/src/client/player.rs +++ b/src/client/player.rs @@ -622,7 +622,7 @@ mod tests { use rstest::rstest; use super::*; - use crate::deobfuscate::DeobfData; + use crate::{deobfuscate::DeobfData, util::tests::TESTFILES}; static DEOBF_DATA: Lazy = Lazy::new(|| { DeobfData { @@ -640,7 +640,7 @@ mod tests { #[case::android("android")] #[case::ios("ios")] fn map_player_data(#[case] name: &str) { - let json_path = path!("testfiles" / "player" / format!("{name}_video.json")); + let json_path = path!(*TESTFILES / "player" / format!("{name}_video.json")); let json_file = File::open(json_path).unwrap(); let resp: response::Player = serde_json::from_reader(BufReader::new(json_file)).unwrap(); diff --git a/src/client/playlist.rs b/src/client/playlist.rs index 37aab8c..2cfad2a 100644 --- a/src/client/playlist.rs +++ b/src/client/playlist.rs @@ -236,7 +236,7 @@ mod tests { use path_macro::path; use rstest::rstest; - use crate::param::Language; + use crate::{param::Language, util::tests::TESTFILES}; use super::*; @@ -245,7 +245,7 @@ mod tests { #[case::long("long", "PL5dDx681T4bR7ZF1IuWzOv1omlRbE7PiJ")] #[case::nomusic("nomusic", "PL1J-6JOckZtE_P9Xx8D3b2O6w0idhuKBe")] fn map_playlist_data(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "playlist" / format!("playlist_{name}.json")); + let json_path = path!(*TESTFILES / "playlist" / format!("playlist_{name}.json")); let json_file = File::open(json_path).unwrap(); let playlist: response::Playlist = @@ -264,7 +264,7 @@ mod tests { #[test] fn map_playlist_cont() { - let json_path = path!("testfiles" / "playlist" / "playlist_cont.json"); + let json_path = path!(*TESTFILES / "playlist" / "playlist_cont.json"); let json_file = File::open(json_path).unwrap(); let playlist: response::PlaylistCont = diff --git a/src/client/response/music_item.rs b/src/client/response/music_item.rs index 54cdd3a..e4995ef 100644 --- a/src/client/response/music_item.rs +++ b/src/client/response/music_item.rs @@ -1064,10 +1064,11 @@ mod tests { use path_macro::path; use super::*; + use crate::util::tests::TESTFILES; #[test] fn map_album_type_samples() { - let json_path = path!("testfiles" / "dict" / "album_type_samples.json"); + let json_path = path!(*TESTFILES / "dict" / "album_type_samples.json"); let json_file = File::open(json_path).unwrap(); let atype_samples: BTreeMap> = serde_json::from_reader(BufReader::new(json_file)).unwrap(); diff --git a/src/client/search.rs b/src/client/search.rs index 475f9f4..895c10e 100644 --- a/src/client/search.rs +++ b/src/client/search.rs @@ -138,6 +138,7 @@ mod tests { model::SearchResult, param::Language, serializer::MapResult, + util::tests::TESTFILES, }; #[rstest] @@ -146,7 +147,7 @@ mod tests { #[case::empty("empty")] #[case::ab3_channel_handles("20221121_AB3_channel_handles")] fn t_map_search(#[case] name: &str) { - let json_path = path!("testfiles" / "search" / format!("{name}.json")); + let json_path = path!(*TESTFILES / "search" / format!("{name}.json")); let json_file = File::open(json_path).unwrap(); let search: response::Search = serde_json::from_reader(BufReader::new(json_file)).unwrap(); diff --git a/src/client/trends.rs b/src/client/trends.rs index 043086a..5d43316 100644 --- a/src/client/trends.rs +++ b/src/client/trends.rs @@ -129,11 +129,12 @@ mod tests { model::{paginator::Paginator, VideoItem}, param::Language, serializer::MapResult, + util::tests::TESTFILES, }; #[test] fn map_startpage() { - let json_path = path!("testfiles" / "trends" / "startpage.json"); + let json_path = path!(*TESTFILES / "trends" / "startpage.json"); let json_file = File::open(json_path).unwrap(); let startpage: response::Startpage = @@ -154,7 +155,7 @@ mod tests { #[test] fn map_trending() { - let json_path = path!("testfiles" / "trends" / "trending.json"); + let json_path = path!(*TESTFILES / "trends" / "trending.json"); let json_file = File::open(json_path).unwrap(); let startpage: response::Trending = diff --git a/src/client/video_details.rs b/src/client/video_details.rs index 2749d5c..40b7aff 100644 --- a/src/client/video_details.rs +++ b/src/client/video_details.rs @@ -543,6 +543,7 @@ mod tests { use crate::{ client::{response, MapResponse}, param::Language, + util::tests::TESTFILES, }; #[rstest] @@ -556,7 +557,7 @@ mod tests { #[case::new_cont("20221011_new_continuation", "ZeerrnuLi5E")] #[case::no_recommends("20221011_rec_isr", "nFDBxBUfE74")] fn map_video_details(#[case] name: &str, #[case] id: &str) { - let json_path = path!("testfiles" / "video_details" / format!("video_details_{name}.json")); + let json_path = path!(*TESTFILES / "video_details" / format!("video_details_{name}.json")); let json_file = File::open(json_path).unwrap(); let details: response::VideoDetails = @@ -576,7 +577,7 @@ mod tests { #[test] fn map_video_details_not_found() { - let json_path = path!("testfiles" / "video_details" / "video_details_not_found.json"); + let json_path = path!(*TESTFILES / "video_details" / "video_details_not_found.json"); let json_file = File::open(json_path).unwrap(); let details: response::VideoDetails = @@ -592,7 +593,7 @@ mod tests { #[case::top("top")] #[case::latest("latest")] fn map_comments(#[case] name: &str) { - let json_path = path!("testfiles" / "video_details" / format!("comments_{name}.json")); + let json_path = path!(*TESTFILES / "video_details" / format!("comments_{name}.json")); let json_file = File::open(json_path).unwrap(); let comments: response::VideoComments = diff --git a/src/deobfuscate.rs b/src/deobfuscate.rs index fd59501..e4b2705 100644 --- a/src/deobfuscate.rs +++ b/src/deobfuscate.rs @@ -288,11 +288,12 @@ fn get_sts(player_js: &str) -> Result { #[cfg(test)] mod tests { use super::*; + use crate::util::tests::TESTFILES; use path_macro::path; use rstest::{fixture, rstest}; static TEST_JS: Lazy = Lazy::new(|| { - let js_path = path!("testfiles" / "deobf" / "dummy_player.js"); + let js_path = path!(*TESTFILES / "deobf" / "dummy_player.js"); std::fs::read_to_string(js_path).unwrap() }); diff --git a/src/param/stream_filter.rs b/src/param/stream_filter.rs index d27fa60..dc178dd 100644 --- a/src/param/stream_filter.rs +++ b/src/param/stream_filter.rs @@ -330,20 +330,22 @@ impl VideoPlayer { mod tests { use std::{fs::File, io::BufReader}; - use super::*; use once_cell::sync::Lazy; use path_macro::path; use rstest::rstest; + use super::*; + use crate::util::tests::TESTFILES; + static PLAYER_ML: Lazy = Lazy::new(|| { - let json_path = path!("testfiles" / "player_model" / "multilanguage.json"); + let json_path = path!(*TESTFILES / "player_model" / "multilanguage.json"); let json_file = File::open(json_path).unwrap(); serde_json::from_reader(BufReader::new(json_file)).unwrap() }); static PLAYER_HDR: Lazy = Lazy::new(|| { - let json_path = path!("testfiles" / "player_model" / "hdr.json"); + let json_path = path!(*TESTFILES / "player_model" / "hdr.json"); let json_file = File::open(json_path).unwrap(); serde_json::from_reader(BufReader::new(json_file)).unwrap() diff --git a/src/serializer/text.rs b/src/serializer/text.rs index c682946..35fb046 100644 --- a/src/serializer/text.rs +++ b/src/serializer/text.rs @@ -485,6 +485,7 @@ mod tests { use serde_with::serde_as; use super::*; + use crate::util::tests::TESTFILES; #[rstest] #[case( @@ -793,7 +794,7 @@ mod tests { #[test] fn t_attributed_description() { - let json_path = path!("testfiles" / "text" / "attributed_description.json"); + let json_path = path!(*TESTFILES / "text" / "attributed_description.json"); let json_file = File::open(json_path).unwrap(); let res: SAttributed = serde_json::from_reader(BufReader::new(json_file)).unwrap(); insta::assert_debug_snapshot!(res); diff --git a/src/timeago.rs b/src/timeago.rs index 8de9a29..f0d7f35 100644 --- a/src/timeago.rs +++ b/src/timeago.rs @@ -302,6 +302,7 @@ mod tests { use time::macros::{date, datetime}; use super::*; + use crate::util::tests::TESTFILES; #[rstest] #[case(Language::De, "vor 1 Sekunde", Some(TimeAgo { n: 1, unit: TimeUnit::Second }))] @@ -319,7 +320,7 @@ mod tests { #[test] fn t_testfile() { - let json_path = path!("testfiles" / "dict" / "timeago_samples.json"); + let json_path = path!(*TESTFILES / "dict" / "timeago_samples.json"); let expect = [ TimeAgo { @@ -500,7 +501,7 @@ mod tests { cases: BTreeMap, } - let json_path = path!("testfiles" / "dict" / "timeago_table.json"); + let json_path = path!(*TESTFILES / "dict" / "timeago_table.json"); let json_file = File::open(json_path).unwrap(); let timeago_table: TimeagoTable = serde_json::from_reader(BufReader::new(json_file)).unwrap(); @@ -545,7 +546,7 @@ mod tests { #[test] fn t_parse_date_samples() { - let json_path = path!("testfiles" / "dict" / "playlist_samples.json"); + let json_path = path!(*TESTFILES / "dict" / "playlist_samples.json"); let json_file = File::open(json_path).unwrap(); let date_samples: BTreeMap> = serde_json::from_reader(BufReader::new(json_file)).unwrap(); diff --git a/src/util/mod.rs b/src/util/mod.rs index bfba647..13c470c 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -363,14 +363,18 @@ pub fn b64_decode>(input: T) -> Result, base64::DecodeErr } #[cfg(test)] -mod tests { - use std::{fs::File, io::BufReader}; +pub(crate) mod tests { + use std::{fs::File, io::BufReader, path::PathBuf}; use path_macro::path; use rstest::rstest; use super::*; + /// Get the path of the `testfiles` directory + pub static TESTFILES: Lazy = + Lazy::new(|| path!(env!("CARGO_MANIFEST_DIR") / "testfiles")); + #[rstest] #[case("1.000", 1000)] #[case("4 Hello World 2", 42)] @@ -450,7 +454,7 @@ mod tests { #[test] fn t_parse_large_numstr_samples() { - let json_path = path!("testfiles" / "dict" / "large_number_samples.json"); + let json_path = path!(*TESTFILES / "dict" / "large_number_samples.json"); let json_file = File::open(json_path).unwrap(); let number_samples: BTreeMap> = serde_json::from_reader(BufReader::new(json_file)).unwrap(); @@ -464,7 +468,7 @@ mod tests { #[test] fn t_parse_large_numstr_samples2() { - let json_path = path!("testfiles" / "dict" / "large_number_samples_all.json"); + let json_path = path!(*TESTFILES / "dict" / "large_number_samples_all.json"); let json_file = File::open(json_path).unwrap(); let number_samples: BTreeMap> = serde_json::from_reader(BufReader::new(json_file)).unwrap();