1pub fn short_id(id: &str) -> String {
2 id.chars().take(8).collect()
3}
4
5#[cfg(test)]
6mod tests {
7 use super::*;
8
9 #[test]
10 fn short_id_truncates_long_ids() {
11 assert_eq!(short_id("1234567890"), "12345678");
12 }
13
14 #[test]
15 fn short_id_returns_input_for_short_strings() {
16 assert_eq!(short_id("abc"), "abc");
17 }
18
19 #[test]
20 fn short_id_returns_input_for_exact_length() {
21 assert_eq!(short_id("12345678"), "12345678");
22 }
23
24 #[test]
25 fn short_id_handles_unicode() {
26 assert_eq!(short_id("ééééééééé"), "éééééééé");
27 }
28}