#[cfg(test)]
macro_rules! example_classes {
() => {{
let mut hm = crate::draft::Classes::new();
hm.insert("C".to_string(), ("[ptk]".to_string(), 0));
hm.insert("V".to_string(), ("[aeiou]".to_string(), 0));
hm.insert("_".to_string(), ("[⟨C⟩⟨V⟩]".to_string(), 0));
hm
}};
}
macro_rules! unrecoverable_error {
( $msg: expr ) => {
(|| {
let len = $msg.len() as i32;
let outer = (len - 49).max(0) as usize;
let inner = (49 - len).max(0) as usize;
eprintln!(
"
┌───────────────────────────────────────────────────────{0}┐
│ Phonet broke! {1}│
│ This is an issue with the source code, not with you. {1}│
│ ┌───────────────────────────────────────────────────{0}┐ │
│ │ {msg} {2}│ │
│ └───────────────────────────────────────────────────{0}┘ │
│ Please create an issue, and include the problem above {1}│
│ https://github.com/darccyy/phonet/issues/new {1}│
└───────────────────────────────────────────────────────{0}┘
",
"─".repeat(outer),
" ".repeat(outer),
" ".repeat(inner),
msg = $msg,
);
panic!("Unrecoverable error");
})()
};
}
pub mod draft;
pub mod error;
pub mod outcome;
mod generate;
pub use crate::{
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");
}
#[test]
#[should_panic]
fn unrecoverable_error_works() {
unrecoverable_error!("whoops!");
}
}