use uroman::{Uroman, rom_format};
pub fn romanize(text: &str) -> String {
Uroman::new()
.romanize_string::<rom_format::Str>(text, None)
.to_string()
}
pub(super) fn romanize_non_roman(text: String) -> String {
if text.is_ascii() {
text
} else {
romanize(&text)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn romanizes_cyrillic_and_keeps_case() {
assert_eq!(romanize("Привет"), "Privet");
}
#[test]
fn leaves_ascii_text_unchanged() {
assert_eq!(romanize("hello, world 42"), "hello, world 42");
assert_eq!(
romanize_non_roman("hello, world 42".to_string()),
"hello, world 42"
);
}
#[test]
fn empty_text_stays_empty() {
assert_eq!(romanize(""), "");
}
#[test]
fn second_step_runs_only_on_non_ascii_text() {
assert_eq!(romanize_non_roman("мир".to_string()), "mir");
}
}