Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anstadnik committed Jun 29, 2023
1 parent c5939a5 commit 3c37f16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bot/src/bot/dialogue/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::REDIS_USERS_SET_KEY;
use anyhow::{Context, Error};
use first_aid_bot_core::prelude::*;
use redis::{aio::MultiplexedConnection, AsyncCommands};
use std::collections::VecDeque;
use teloxide::dispatching::DpHandlerDescription;
use teloxide::prelude::*;
use teloxide::types::ParseMode::Html;
Expand Down Expand Up @@ -73,11 +72,14 @@ pub async fn easter_egg(bot: &FABot, msg: &Message) -> Result<(), Error> {
}

async fn recursive_test(fs: &Fs, ctx: FAContext, bot: &FABot, msg: &Message) -> anyhow::Result<()> {
let mut q: VecDeque<_> = [(fs, ctx)].into();
while let Some((fs, ctx)) = q.pop_front() {
send_state(bot, msg, &ctx, fs)
.await
.with_context(|| format!("Error while processing state {ctx}"))?;
let mut q = vec![(fs, ctx)];
while let Some((fs, ctx)) = q.pop() {
send_state(bot, msg, &ctx, fs).await.with_context(|| {
format!(
"Error while processing state {ctx}. Message is {}",
fs.message
)
})?;
q.extend(fs.next_states.iter().map(|(s, fs)| {
let mut ctx = ctx.clone();
ctx.transition(s.to_string());
Expand Down
6 changes: 6 additions & 0 deletions core/tests/test_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ fn test_md(s: &str) -> Result<()> {
}

fn test_fs(fs: Fs) -> Result<()> {
if fs.message.chars().all(char::is_whitespace) {
bail!("Empty message");
}
if fs.link.as_ref().is_some_and(|s| s.chars().all(char::is_whitespace)) {
bail!("Empty link");
}
test_md(&fs.message)?;
for (s, fs) in fs.next_states {
test_fs(fs).context(s)?;
Expand Down

0 comments on commit 3c37f16

Please sign in to comment.