Port skybot hash plugin as a module
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
b312ff0338
commit
d9e279d8ed
4 changed files with 333 additions and 4 deletions
76
tests/hash.rs
Normal file
76
tests/hash.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
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" }
|
||||
}
|
||||
|
||||
fn reply(actions: &[Action]) -> &str {
|
||||
match actions {
|
||||
[Action::Reply(s)] => s,
|
||||
_ => panic!("expected exactly one Reply"),
|
||||
}
|
||||
}
|
||||
|
||||
const MULTI: &[u8] = b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
|
||||
#[test]
|
||||
fn md5_vectors() {
|
||||
assert_eq!(md5(b""), "d41d8cd98f00b204e9800998ecf8427e");
|
||||
assert_eq!(md5(b"abc"), "900150983cd24fb0d6963f7d28e17f72");
|
||||
assert_eq!(
|
||||
md5(b"The quick brown fox jumps over the lazy dog"),
|
||||
"9e107d9d372bb6826bd81d3542a419d6"
|
||||
);
|
||||
assert_eq!(
|
||||
md5(b"12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
"57edf4a22be3c955ac49da2e2107b67a"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sha1_vectors() {
|
||||
assert_eq!(sha1(b""), "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||
assert_eq!(sha1(b"abc"), "a9993e364706816aba3e25717850c26c9cd0d89d");
|
||||
assert_eq!(sha1(MULTI), "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sha256_vectors() {
|
||||
assert_eq!(
|
||||
sha256(b""),
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
);
|
||||
assert_eq!(
|
||||
sha256(b"abc"),
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
);
|
||||
assert_eq!(
|
||||
sha256(MULTI),
|
||||
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_single_hash() {
|
||||
let mut m = Hash;
|
||||
assert_eq!(
|
||||
reply(&m.on_command(&cmd("sha256", &["abc"]))),
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
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}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_usage_when_empty() {
|
||||
let mut m = Hash;
|
||||
assert!(reply(&m.on_command(&cmd("md5", &[]))).contains("usage"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue