From 3c37f1631073de5a7052d43db4fb7c308e615cee Mon Sep 17 00:00:00 2001 From: Stadnik Andrii Date: Thu, 29 Jun 2023 20:28:47 +0300 Subject: [PATCH] Update tests --- bot/src/bot/dialogue/commands.rs | 14 ++++++++------ core/tests/test_data.rs | 6 ++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bot/src/bot/dialogue/commands.rs b/bot/src/bot/dialogue/commands.rs index 99bdf999..f3214b53 100644 --- a/bot/src/bot/dialogue/commands.rs +++ b/bot/src/bot/dialogue/commands.rs @@ -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; @@ -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()); diff --git a/core/tests/test_data.rs b/core/tests/test_data.rs index 851552cf..43559cc0 100644 --- a/core/tests/test_data.rs +++ b/core/tests/test_data.rs @@ -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)?;