Add more asserts to tests
This commit is contained in:
parent
ee02e2c80d
commit
4ed0cadeb8
|
@ -28,17 +28,18 @@ pub async fn score(_ctx: Context<'_>) -> Result<(), Error> {
|
||||||
async fn magic_impl<C: MessageContext>(
|
async fn magic_impl<C: MessageContext>(
|
||||||
ctx: &mut C,
|
ctx: &mut C,
|
||||||
files: Vec<C::Attachment>,
|
files: Vec<C::Attachment>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<Vec<Play>, Error> {
|
||||||
let user = get_user!(ctx);
|
let user = get_user!(ctx);
|
||||||
let files = ctx.download_images(&files).await?;
|
let files = ctx.download_images(&files).await?;
|
||||||
|
|
||||||
if files.len() == 0 {
|
if files.len() == 0 {
|
||||||
ctx.reply("No images found attached to message").await?;
|
ctx.reply("No images found attached to message").await?;
|
||||||
return Ok(());
|
return Ok(vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut embeds = Vec::with_capacity(files.len());
|
let mut embeds = Vec::with_capacity(files.len());
|
||||||
let mut attachments = Vec::with_capacity(files.len());
|
let mut attachments = Vec::with_capacity(files.len());
|
||||||
|
let mut plays = Vec::with_capacity(files.len());
|
||||||
let mut analyzer = ImageAnalyzer::default();
|
let mut analyzer = ImageAnalyzer::default();
|
||||||
|
|
||||||
for (i, (attachment, bytes)) in files.into_iter().enumerate() {
|
for (i, (attachment, bytes)) in files.into_iter().enumerate() {
|
||||||
|
@ -116,6 +117,7 @@ async fn magic_impl<C: MessageContext>(
|
||||||
play.to_embed(ctx.data(), &user, &song, &chart, i, None)?
|
play.to_embed(ctx.data(), &user, &song, &chart, i, None)?
|
||||||
});
|
});
|
||||||
|
|
||||||
|
plays.push(play);
|
||||||
embeds.push(embed);
|
embeds.push(embed);
|
||||||
attachments.extend(attachment);
|
attachments.extend(attachment);
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -133,7 +135,7 @@ async fn magic_impl<C: MessageContext>(
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(plays)
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ Tests
|
// {{{ Tests
|
||||||
|
@ -142,10 +144,16 @@ mod magic_tests {
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::with_test_ctx;
|
use crate::{
|
||||||
|
arcaea::score::ScoringSystem, commands::discord::mock::MockContext, with_test_ctx,
|
||||||
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
fn play_song_title<'a>(ctx: &'a MockContext, play: &'a Play) -> Result<&'a str, Error> {
|
||||||
|
Ok(&ctx.data().song_cache.lookup_chart(play.chart_id)?.0.title)
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn no_pics() -> Result<(), Error> {
|
async fn no_pics() -> Result<(), Error> {
|
||||||
with_test_ctx!("test/commands/score/magic/no_pics", async |ctx| {
|
with_test_ctx!("test/commands/score/magic/no_pics", async |ctx| {
|
||||||
|
@ -156,20 +164,28 @@ mod magic_tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn simple_pic() -> Result<(), Error> {
|
async fn simple_pic() -> Result<(), Error> {
|
||||||
with_test_ctx!("test/commands/score/magic/single_pic", async |ctx| {
|
with_test_ctx!(
|
||||||
magic_impl(
|
"test/commands/score/magic/single_pic",
|
||||||
|
async |ctx: &mut MockContext| {
|
||||||
|
let plays = magic_impl(
|
||||||
ctx,
|
ctx,
|
||||||
vec![PathBuf::from_str("test/screenshots/alter_ego.jpg")?],
|
vec![PathBuf::from_str("test/screenshots/alter_ego.jpg")?],
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
assert_eq!(plays.len(), 1);
|
||||||
|
assert_eq!(plays[0].score(ScoringSystem::Standard).0, 9926250);
|
||||||
|
assert_eq!(play_song_title(ctx, &plays[0])?, "ALTER EGO");
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn weird_kerning() -> Result<(), Error> {
|
async fn weird_kerning() -> Result<(), Error> {
|
||||||
with_test_ctx!("test/commands/score/magic/weird_kerning", async |ctx| {
|
with_test_ctx!(
|
||||||
magic_impl(
|
"test/commands/score/magic/weird_kerning",
|
||||||
|
async |ctx: &mut MockContext| {
|
||||||
|
let plays = magic_impl(
|
||||||
ctx,
|
ctx,
|
||||||
vec![
|
vec![
|
||||||
PathBuf::from_str("test/screenshots/antithese_74_kerning.jpg")?,
|
PathBuf::from_str("test/screenshots/antithese_74_kerning.jpg")?,
|
||||||
|
@ -177,8 +193,16 @@ mod magic_tests {
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
assert_eq!(plays.len(), 2);
|
||||||
|
assert_eq!(plays[0].score(ScoringSystem::Standard).0, 9983744);
|
||||||
|
assert_eq!(play_song_title(ctx, &plays[0])?, "Antithese");
|
||||||
|
assert_eq!(plays[1].score(ScoringSystem::Standard).0, 9724775);
|
||||||
|
assert_eq!(play_song_title(ctx, &plays[1])?, "GENOCIDER");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
|
|
|
@ -31,13 +31,16 @@ macro_rules! assert_is_pookie {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! reply_errors {
|
macro_rules! reply_errors {
|
||||||
($ctx:expr, $value:expr) => {
|
($ctx:expr, $default:expr, $value:expr) => {
|
||||||
match $value {
|
match $value {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
crate::commands::discord::MessageContext::reply($ctx, &format!("{err}")).await?;
|
crate::commands::discord::MessageContext::reply($ctx, &format!("{err}")).await?;
|
||||||
return Ok(());
|
return Ok($default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
($ctx:expr, $value:expr) => {
|
||||||
|
crate::reply_errors!($ctx, Default::default(), $value)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue