1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
pub mod draft;
pub mod error;
pub mod outcome;
mod color;
mod generate;
pub use crate::{
color::colorize,
draft::Draft,
outcome::{DisplayLevel, Outcome},
};
const REGEX_MATCH_FAIL: &str = "Regex failed on 'match' method. This should never happen";
pub fn get_min_filename(file: &str) -> String {
let mut split = file.split('.');
let ext = match split.next_back() {
None | Some("") => return String::new(),
Some(string) => string,
};
let rest: Vec<&str> = split.collect();
if !rest.is_empty() {
rest.join(".") + ".min." + ext
} else {
"min.".to_string() + ext
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn get_min_filename_works() {
assert_eq!(get_min_filename(""), "");
assert_eq!(get_min_filename("phonet"), "min.phonet");
assert_eq!(get_min_filename("myfile.phonet"), "myfile.min.phonet");
assert_eq!(get_min_filename("one.two.phonet"), "one.two.min.phonet");
}
}