1use std::path::{Path, PathBuf};
2
3const GENERATED_BASE: &str = "crates/mig-types/src/generated";
5
6pub fn schema_dir(format_version: &str, message_type: &str) -> PathBuf {
13 Path::new(GENERATED_BASE)
14 .join(format_version.to_lowercase())
15 .join(message_type.to_lowercase())
16 .join("pids")
17}
18
19pub fn pid_schema_file(format_version: &str, message_type: &str, pid: &str) -> PathBuf {
24 schema_dir(format_version, message_type).join(format!("pid_{pid}_schema.json"))
25}
26
27pub fn generated_base() -> &'static Path {
29 Path::new(GENERATED_BASE)
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn test_schema_dir() {
38 assert_eq!(
39 schema_dir("FV2504", "UTILMD"),
40 PathBuf::from("crates/mig-types/src/generated/fv2504/utilmd/pids")
41 );
42 }
43
44 #[test]
45 fn test_schema_dir_case_insensitive() {
46 assert_eq!(
47 schema_dir("fv2504", "utilmd"),
48 schema_dir("FV2504", "UTILMD")
49 );
50 }
51
52 #[test]
53 fn test_pid_schema_file() {
54 assert_eq!(
55 pid_schema_file("FV2504", "UTILMD", "55001"),
56 PathBuf::from(
57 "crates/mig-types/src/generated/fv2504/utilmd/pids/pid_55001_schema.json"
58 )
59 );
60 }
61
62 #[test]
63 fn test_generated_base() {
64 assert_eq!(
65 generated_base(),
66 Path::new("crates/mig-types/src/generated")
67 );
68 }
69}