Un use the assert_match in the tests

This commit is contained in:
Anas Elgarhy 2023-04-08 23:42:21 +02:00
parent 8674a03bf0
commit 15c7b9bd04
No known key found for this signature in database
GPG key ID: 0501802A1D496528
2 changed files with 26 additions and 14 deletions

View file

@ -304,7 +304,6 @@ pub fn build_query_command(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::assert_matches::assert_matches;
const OUTPUT_WITH_ALL_TAGS: &str = const OUTPUT_WITH_ALL_TAGS: &str =
include_str!("../../tests/samples/cmus-remote-output-with-all-tags.txt"); include_str!("../../tests/samples/cmus-remote-output-with-all-tags.txt");
@ -329,7 +328,8 @@ mod tests {
fn test_create_track_from_str() { fn test_create_track_from_str() {
let track = Track::from_str(OUTPUT_WITH_ALL_TAGS); let track = Track::from_str(OUTPUT_WITH_ALL_TAGS);
assert_matches!(track, Ok(_)); // assert_matches!(track, Ok(_));
assert!(track.is_ok());
let track = track.unwrap(); let track = track.unwrap();

View file

@ -1,5 +1,3 @@
#![feature(assert_matches)]
use crate::cmus::{TemplateProcessor, Track}; use crate::cmus::{TemplateProcessor, Track};
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
use log::{debug, info}; use log::{debug, info};
@ -232,7 +230,6 @@ pub fn process_template_placeholders(
mod tests { mod tests {
use super::*; use super::*;
use crate::cmus::player_settings::PlayerSettings; use crate::cmus::player_settings::PlayerSettings;
use std::assert_matches::assert_matches;
use std::str::FromStr; use std::str::FromStr;
use test_context::{test_context, TestContext}; use test_context::{test_context, TestContext};
@ -277,9 +274,12 @@ mod tests {
&regex::Regex::new(r"cover|.\.jpg|.\.png").unwrap(), &regex::Regex::new(r"cover|.\.jpg|.\.png").unwrap(),
); );
assert_matches!(cover_path, Ok(Some(_))); // assert_matches!(cover_path, Ok(Some(_)));
assert!(cover_path.is_ok());
let cover_path = cover_path.unwrap();
assert!(cover_path.is_some());
assert_eq!( assert_eq!(
cover_path.unwrap().unwrap(), cover_path.unwrap(),
"tests/samples/Owl City/Cinematic/cover/cover.jpg" "tests/samples/Owl City/Cinematic/cover/cover.jpg"
); );
} }
@ -292,9 +292,12 @@ mod tests {
&regex::Regex::new(r".\.jpg|.\.png").unwrap(), &regex::Regex::new(r".\.jpg|.\.png").unwrap(),
); );
assert_matches!(cover_path, Ok(Some(_))); // assert_matches!(cover_path, Ok(Some(_)));
assert!(cover_path.is_ok());
let cover_path = cover_path.unwrap();
assert!(cover_path.is_some());
assert_eq!( assert_eq!(
cover_path.unwrap().unwrap(), cover_path.unwrap(),
"tests/samples/Owl City/Cinematic/cover/cover.jpg" "tests/samples/Owl City/Cinematic/cover/cover.jpg"
); );
} }
@ -307,9 +310,12 @@ mod tests {
&regex::Regex::new(r".\.png").unwrap(), &regex::Regex::new(r".\.png").unwrap(),
); );
assert_matches!(cover_path, Ok(Some(_))); // assert_matches!(cover_path, Ok(Some(_)));
assert!(cover_path.is_ok());
let cover_path = cover_path.unwrap();
assert!(cover_path.is_some());
assert_eq!( assert_eq!(
cover_path.unwrap().unwrap(), cover_path.unwrap(),
"tests/samples/Owl City/Cinematic/cover/cover.png" "tests/samples/Owl City/Cinematic/cover/cover.png"
); );
} }
@ -322,9 +328,12 @@ mod tests {
&regex::Regex::new(r".\.lrc").unwrap(), &regex::Regex::new(r".\.lrc").unwrap(),
); );
assert_matches!(lrc_path, Ok(Some(_))); // assert_matches!(lrc_path, Ok(Some(_)));
assert!(lrc_path.is_ok());
let lrc_path = lrc_path.unwrap();
assert!(lrc_path.is_some());
assert_eq!( assert_eq!(
lrc_path.unwrap().unwrap(), lrc_path.unwrap(),
"tests/samples/Owl City/Cinematic/08 - Always.lrc" "tests/samples/Owl City/Cinematic/08 - Always.lrc"
); );
} }
@ -337,6 +346,9 @@ mod tests {
&regex::Regex::new(r".\.mp3").unwrap(), &regex::Regex::new(r".\.mp3").unwrap(),
); );
assert_matches!(result, Ok(None)); // assert_matches!(result, Ok(None));
assert!(result.is_ok());
let result = result.unwrap();
assert!(result.is_none());
} }
} }