<commit_before>use crate::discord_client::CommandHandler;

pub struct PingCommand;

impl CommandHandler for PingCommand {
    fn process_command(
        &self,
        _command: &str,
        send_message_callback: &Fn(&str) -> (),
    ) -> Result<(), Box<std::error::Error>> {
        send_message_callback("Pong!");

        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use std::sync::{Arc, Mutex};
    use std::thread;
    use std::time::{Duration, Instant};
    use super::*;

    #[test]
    fn test_ping() {
        let ping = PingCommand;

        let result = Arc::new(Mutex::new(Box::new(String::new())));
        let closure_result = result.clone();
        assert!(ping.process_command("", &|message| *closure_result.lock().unwrap() = Box::new(String::from(message))).is_ok());

        let expected_message = String::from("Pong!");
        let timeout = Instant::now();
        while (timeout.elapsed() < Duration::from_secs(2)) && (**result.lock().unwrap() != expected_message) {
            thread::sleep(Duration::from_millis(200));<commit_msg>run rustfmt<commit_after>use crate::discord_client::CommandHandler;

pub struct PingCommand;

impl CommandHandler for PingCommand {
    fn process_command(
        &self,
        _command: &str,
        send_message_callback: &Fn(&str) -> (),
    ) -> Result<(), Box<std::error::Error>> {
        send_message_callback("Pong!");

        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::sync::{Arc, Mutex};
    use std::thread;
    use std::time::{Duration, Instant};

    #[test]
    fn test_ping() {
        let ping = PingCommand;

        let result = Arc::new(Mutex::new(Box::new(String::new())));
        let closure_result = result.clone();
        assert!(ping
            .process_command("", &|message| *closure_result.lock().unwrap() =
                Box::new(String::from(message)))
            .is_ok());

        let expected_message = String::from("Pong!");
        let timeout = Instant::now();
        while (timeout.elapsed() < Duration::from_secs(2))
            && (**result.lock().unwrap() != expected_message)
        {
            thread::sleep(Duration::from_millis(200));
{'fraction_non_alphanumeric': 0.1779816513761468, 'fraction_numerical': 0.003669724770642202, 'mean_word_length': 2.9945054945054945, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '194642', 'n_tokens_mistral': 680, 'n_tokens_neox': 669, 'n_words': 124}