use std::path::{Path, PathBuf};
const GENERATED_BASE: &str = "crates/mig-types/src/generated";
pub fn schema_dir(format_version: &str, message_type: &str) -> PathBuf {
Path::new(GENERATED_BASE)
.join(format_version.to_lowercase())
.join(message_type.to_lowercase())
.join("pids")
}
pub fn pid_schema_file(format_version: &str, message_type: &str, pid: &str) -> PathBuf {
schema_dir(format_version, message_type).join(format!("pid_{pid}_schema.json"))
}
pub fn generated_base() -> &'static Path {
Path::new(GENERATED_BASE)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_schema_dir() {
assert_eq!(
schema_dir("FV2504", "UTILMD"),
PathBuf::from("crates/mig-types/src/generated/fv2504/utilmd/pids")
);
}
#[test]
fn test_schema_dir_case_insensitive() {
assert_eq!(
schema_dir("fv2504", "utilmd"),
schema_dir("FV2504", "UTILMD")
);
}
#[test]
fn test_pid_schema_file() {
assert_eq!(
pid_schema_file("FV2504", "UTILMD", "55001"),
PathBuf::from(
"crates/mig-types/src/generated/fv2504/utilmd/pids/pid_55001_schema.json"
)
);
}
#[test]
fn test_generated_base() {
assert_eq!(
generated_base(),
Path::new("crates/mig-types/src/generated")
);
}
}