zerodds_corba_codegen/
repository_id.rs1use alloc::format;
11use alloc::string::String;
12
13#[must_use]
19pub fn build_repository_id(modules: &[&str], type_name: &str, major: u16, minor: u16) -> String {
20 let mut path = String::new();
21 for (i, m) in modules.iter().enumerate() {
22 if i > 0 {
23 path.push('/');
24 }
25 path.push_str(m);
26 }
27 if !modules.is_empty() {
28 path.push('/');
29 }
30 path.push_str(type_name);
31 format!("IDL:{path}:{major}.{minor}")
32}
33
34#[cfg(test)]
35#[allow(clippy::expect_used, clippy::unwrap_used, clippy::panic)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn flat_module_path() {
41 let s = build_repository_id(&["demo"], "Echo", 1, 0);
42 assert_eq!(s, "IDL:demo/Echo:1.0");
43 }
44
45 #[test]
46 fn nested_module_path() {
47 let s = build_repository_id(&["MyApp", "Trading"], "Order", 1, 0);
48 assert_eq!(s, "IDL:MyApp/Trading/Order:1.0");
49 }
50
51 #[test]
52 fn root_level_no_modules() {
53 let s = build_repository_id(&[], "Object", 1, 0);
54 assert_eq!(s, "IDL:Object:1.0");
55 }
56
57 #[test]
58 fn version_propagates() {
59 let s = build_repository_id(&["x"], "Y", 2, 5);
60 assert_eq!(s, "IDL:x/Y:2.5");
61 }
62}