texting/bracket/
mod.rs

1use crate::enums::Brac;
2
3pub fn br(text: &str, brac: &Brac) -> String {
4    match brac {
5        Brac::Par => { format!("({})", text) }
6        Brac::Brk => { format!("[{}]", text) }
7        Brac::Brc => { format!("{{{}}}", text) }
8        Brac::Ang => { format!("<{}>", text) }
9        Brac::Nan => { String::from(text) }
10    }
11}
12
13
14#[cfg(test)]
15mod tests {
16    use veho::vector::iterate;
17
18    use super::*;
19
20    #[test]
21    fn test() {
22        let candidates = [
23            Brac::Par,
24            Brac::Brk,
25            Brac::Brc,
26            Brac::Ang,
27            Brac::Nan,
28        ];
29        let text = "refresh yourself";
30        iterate(&candidates, |brac| {
31            println!("{} {}", text, br(text, brac));
32        });
33    }
34}