mod custom_options;
mod generated;
mod schema;
mod script_data;
mod script_list;
use std::collections::HashMap;
pub use custom_options::*;
pub use schema::*;
pub use script_list::*;
pub fn get_all_options(
from_script_name: &str,
to_script_name: &str,
) -> Result<Vec<String>, String> {
let normalized_from = get_normalized_script_name(from_script_name)
.ok_or_else(|| format!("Invalid script name: {}", from_script_name))?;
let normalized_to = get_normalized_script_name(to_script_name)
.ok_or_else(|| format!("Invalid script name: {}", to_script_name))?;
let from_script_data = ScriptData::get_script_data(&normalized_from);
let to_script_data = ScriptData::get_script_data(&normalized_to);
let custom_options_map = get_custom_options_map();
let all_options_enabled: HashMap<String, bool> = custom_options_map
.keys()
.map(|key| (key.clone(), true))
.collect();
let active_options = crate::transliterate::transliterate::get_active_custom_options(
from_script_data,
to_script_data,
Some(&all_options_enabled),
);
let mut ordered: Vec<String> = Vec::new();
for key in custom_options_map.keys() {
if active_options.contains_key(key) {
ordered.push(key.clone());
}
}
Ok(ordered)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_all_option_valid_scripts() {
let result = get_all_options("Devanagari", "Telugu");
assert!(result.is_ok());
}
#[test]
fn test_get_all_option_normalized_names() {
let result = get_all_options("dev", "tel");
assert!(result.is_ok());
}
#[test]
fn test_get_all_option_invalid_from_script() {
let result = get_all_options("InvalidScript", "Telugu");
assert!(result.is_err());
assert_eq!(result.unwrap_err(), "Invalid script name: InvalidScript");
}
#[test]
fn test_get_all_option_invalid_to_script() {
let result = get_all_options("Devanagari", "InvalidScript");
assert!(result.is_err());
assert_eq!(result.unwrap_err(), "Invalid script name: InvalidScript");
}
}