teloxide/tests/bot_dialogue.rs
2021-12-29 13:33:51 +02:00

64 lines
1.5 KiB
Rust

#[cfg(feature = "macros")]
use teloxide::macros::DialogueState;
// We put tests here because macro expand in unit tests in the crate was a
// failure
#[test]
#[cfg(feature = "macros")]
fn compile_test() {
#[allow(dead_code)]
#[derive(DialogueState, Clone)]
#[out(Result<(), teloxide::RequestError>)]
#[store(teloxide::dispatching2::dialogue::InMemStorage<State>)]
enum State {
#[handler(handle_start)]
Start,
#[handler(handle_have_data)]
HaveData(String),
}
impl Default for State {
fn default() -> Self {
Self::Start
}
}
async fn handle_start() -> Result<(), teloxide::RequestError> {
Ok(())
}
async fn handle_have_data() -> Result<(), teloxide::RequestError> {
Ok(())
}
}
#[test]
#[cfg(feature = "macros")]
fn compile_test_generics() {
#[allow(dead_code)]
#[derive(DialogueState, Clone)]
#[out(Result<(), teloxide::RequestError>)]
#[store(teloxide::dispatching2::dialogue::InMemStorage<State<X>>)]
enum State<X: Clone + Send + Sync + 'static> {
#[handler(handle_start)]
Start,
#[handler(handle_have_data)]
HaveData(X),
}
impl<X: Clone + Send + Sync + 'static> Default for State<X> {
fn default() -> Self {
Self::Start
}
}
async fn handle_start() -> Result<(), teloxide::RequestError> {
Ok(())
}
async fn handle_have_data() -> Result<(), teloxide::RequestError> {
Ok(())
}
}