1use super::Finder;
7use std::ops::Range;
8
9#[derive(Default)]
26pub struct Mirror {}
27
28impl Finder for Mirror {
29 fn id(&self) -> &'static str {
30 "mirror"
31 }
32
33 fn find(&self, s: &str) -> Option<Range<usize>> {
34 Some(0..s.len())
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn id_should_return_mirror() {
44 let finder = Mirror::default();
45 assert_eq!("mirror", finder.id());
46 }
47
48 #[test]
49 fn find_should_return_full_range_for_non_empty_string() {
50 let finder = Mirror::default();
51 let input = "hello world";
52 assert_eq!(Some(0..11), finder.find(input));
53 }
54
55 #[test]
56 fn find_should_return_empty_range_for_empty_string() {
57 let finder = Mirror::default();
58 assert_eq!(Some(0..0), finder.find(""));
59 }
60
61 #[test]
62 fn find_should_return_full_range_for_unicode() {
63 let finder = Mirror::default();
64 let input = "héllo 世界 🦀";
65 assert_eq!(Some(0..input.len()), finder.find(input));
66 }
67
68 #[test]
69 fn find_should_return_full_range_for_whitespace() {
70 let finder = Mirror::default();
71 assert_eq!(Some(0..3), finder.find(" "));
72 assert_eq!(Some(0..2), finder.find("\t\n"));
73 }
74}