haystack_core/ontology/
lib.rs1use std::collections::HashMap;
4
5use super::def::Def;
6
7#[derive(Debug, Clone)]
12pub struct Lib {
13 pub name: String,
15 pub version: String,
17 pub doc: String,
19 pub depends: Vec<String>,
21 pub defs: HashMap<String, Def>,
23}
24
25impl Lib {
26 pub fn new(name: impl Into<String>) -> Self {
28 Self {
29 name: name.into(),
30 version: String::new(),
31 doc: String::new(),
32 depends: vec![],
33 defs: HashMap::new(),
34 }
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41 use crate::data::HDict;
42
43 #[test]
44 fn new_lib_defaults() {
45 let lib = Lib::new("phIoT");
46 assert_eq!(lib.name, "phIoT");
47 assert_eq!(lib.version, "");
48 assert_eq!(lib.doc, "");
49 assert!(lib.depends.is_empty());
50 assert!(lib.defs.is_empty());
51 }
52
53 #[test]
54 fn lib_with_defs() {
55 let mut lib = Lib::new("test");
56 lib.version = "1.0.0".to_string();
57 lib.defs.insert(
58 "site".to_string(),
59 Def {
60 symbol: "site".to_string(),
61 lib: "test".to_string(),
62 is_: vec!["marker".to_string()],
63 tag_on: vec![],
64 of: None,
65 mandatory: false,
66 doc: "A site".to_string(),
67 tags: HDict::new(),
68 },
69 );
70 assert_eq!(lib.defs.len(), 1);
71 assert!(lib.defs.contains_key("site"));
72 }
73}