Format with rustfmt
All checks were successful
ci / check (push) Successful in 44s

This commit is contained in:
Jean Chevronnet 2026-07-29 19:17:16 +00:00
parent facbde55bd
commit 7846f91afe
No known key found for this signature in database
GPG key ID: 439666D63A9477E4
11 changed files with 209 additions and 54 deletions

View file

@ -2,7 +2,14 @@ use rustbot::bot::module::{Action, Command, Module};
use rustbot::bot::modules::hash::{md5, sha1, sha256, Hash};
fn cmd<'a>(name: &'a str, args: &'a [&'a str]) -> Command<'a> {
Command { sender: "u", reply_to: "#c", name, args, prefix: ">", network: "t" }
Command {
sender: "u",
reply_to: "#c",
name,
args,
prefix: ">",
network: "t",
}
}
fn reply(actions: &[Action]) -> &str {
@ -65,8 +72,14 @@ fn module_all_hashes() {
let mut m = Hash;
let r = reply(&m.on_command(&cmd("hash", &["abc"]))).to_string();
assert!(r.contains("md5: 900150983cd24fb0d6963f7d28e17f72"), "{r}");
assert!(r.contains("sha1: a9993e364706816aba3e25717850c26c9cd0d89d"), "{r}");
assert!(r.contains("sha256: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"), "{r}");
assert!(
r.contains("sha1: a9993e364706816aba3e25717850c26c9cd0d89d"),
"{r}"
);
assert!(
r.contains("sha256: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
"{r}"
);
}
#[test]

View file

@ -2,7 +2,14 @@ use rustbot::bot::module::{Action, Command, Module};
use rustbot::bot::modules::{builtins::Builtins, dice::Dice};
fn cmd<'a>(name: &'a str, args: &'a [&'a str]) -> Command<'a> {
Command { sender: "alice", reply_to: "#chan", name, args, prefix: ">", network: "test" }
Command {
sender: "alice",
reply_to: "#chan",
name,
args,
prefix: ">",
network: "test",
}
}
fn reply(actions: &[Action]) -> &str {
@ -21,7 +28,10 @@ fn builtins_ping_pongs() {
#[test]
fn builtins_echo_joins_args() {
let mut m = Builtins;
assert_eq!(reply(&m.on_command(&cmd("echo", &["hello", "world"]))), "hello world");
assert_eq!(
reply(&m.on_command(&cmd("echo", &["hello", "world"]))),
"hello world"
);
}
#[test]
@ -43,7 +53,10 @@ fn dice_2d6_total_is_in_range() {
for _ in 0..300 {
let r = reply(&d.on_command(&cmd("roll", &["2d6"]))).to_string();
let total: u64 = r.rsplit('=').next().unwrap().trim().parse().unwrap();
assert!((2..=12).contains(&total), "2d6 total {total} out of range: {r:?}");
assert!(
(2..=12).contains(&total),
"2d6 total {total} out of range: {r:?}"
);
}
}

View file

@ -61,8 +61,14 @@ fn base64_matches_known_vectors() {
#[test]
fn server_time_parses_to_unix_seconds() {
assert_eq!(parse_server_time("1970-01-01T00:00:00.000Z"), Some(0));
assert_eq!(parse_server_time("2020-01-01T00:00:00Z"), Some(1_577_836_800));
assert_eq!(parse_server_time("2021-01-01T00:00:00.123Z"), Some(1_609_459_200));
assert_eq!(
parse_server_time("2020-01-01T00:00:00Z"),
Some(1_577_836_800)
);
assert_eq!(
parse_server_time("2021-01-01T00:00:00.123Z"),
Some(1_609_459_200)
);
assert_eq!(parse_server_time("not-a-timestamp"), None);
}

View file

@ -5,7 +5,14 @@ use rustbot::bot::module::{Action, Command, Module};
use rustbot::bot::modules::weather::{format_weather, parse_db, to_json, Weather};
fn cmd<'a>(sender: &'a str, name: &'a str, args: &'a [&'a str]) -> Command<'a> {
Command { sender, reply_to: "#chan", name, args, prefix: ">", network: "test" }
Command {
sender,
reply_to: "#chan",
name,
args,
prefix: ">",
network: "test",
}
}
fn reply(actions: &[Action]) -> &str {
@ -36,7 +43,10 @@ fn parse_db_tolerates_junk() {
assert!(parse_db("").is_empty());
assert!(parse_db("not json").is_empty());
assert_eq!(parse_db("{}").len(), 0);
assert_eq!(parse_db("{\"a\":\"b\"}").get("a").map(String::as_str), Some("b"));
assert_eq!(
parse_db("{\"a\":\"b\"}").get("a").map(String::as_str),
Some("b")
);
}
#[test]