daipendency_extractor/
types.rs1#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2pub struct Namespace {
3 pub name: String,
4 pub symbols: Vec<Symbol>,
5 pub doc_comment: Option<String>,
6}
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct Symbol {
10 pub name: String,
11 pub source_code: String,
12}
13
14impl Namespace {
15 pub fn get_symbol(&self, name: &str) -> Option<&Symbol> {
16 self.symbols.iter().find(|s| s.name == name)
17 }
18}
19
20#[cfg(test)]
21mod tests {
22 use assertables::{assert_none, assert_some};
23
24 use super::*;
25
26 #[test]
27 fn get_symbol_found() {
28 let symbol = Symbol {
29 name: "test_symbol".to_string(),
30 source_code: "fn test() {}".to_string(),
31 };
32 let namespace = Namespace {
33 name: "test_namespace".to_string(),
34 symbols: vec![symbol],
35 doc_comment: None,
36 };
37
38 let found = namespace.get_symbol("test_symbol");
39
40 assert_some!(found);
41 assert_eq!(found.unwrap().name, "test_symbol");
42 }
43
44 #[test]
45 fn get_symbol_not_found() {
46 let namespace = Namespace {
47 name: "test_namespace".to_string(),
48 symbols: vec![],
49 doc_comment: None,
50 };
51
52 let symbol = namespace.get_symbol("nonexistent");
53
54 assert_none!(symbol);
55 }
56}