From 2a02694758cc0135c09564ffce65abe9c348f5ad Mon Sep 17 00:00:00 2001 From: bouzuya Date: Tue, 21 Feb 2023 23:44:34 +0900 Subject: [PATCH] twiq-light: Add test for tweet_length --- twiq-light/src/command/enqueue.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/twiq-light/src/command/enqueue.rs b/twiq-light/src/command/enqueue.rs index fafc33db..2c5173ef 100644 --- a/twiq-light/src/command/enqueue.rs +++ b/twiq-light/src/command/enqueue.rs @@ -17,3 +17,22 @@ pub async fn run( store.write_all(&queue).await?; Ok(()) } + +#[cfg(test)] +mod tests { + fn check(s: &str) -> bool { + if s.len() > 6 * 140 { + return false; + } + s.chars() + .map(|c| if c.is_ascii_alphanumeric() { 1 } else { 2 }) + .sum::() + <= 280 + } + + #[test] + fn test() { + assert!(check("a".repeat(280).as_str())); + assert!(check("0".repeat(280).as_str())); + } +}