Skip to content

Commit

Permalink
twiq-light: Add test for tweet_length
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Feb 21, 2023
1 parent aeaf1cc commit 2a02694
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions twiq-light/src/command/enqueue.rs
Expand Up @@ -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::<usize>()
<= 280
}

#[test]
fn test() {
assert!(check("a".repeat(280).as_str()));
assert!(check("0".repeat(280).as_str()));
}
}

0 comments on commit 2a02694

Please sign in to comment.