codegraph_python/relationships/
inheritance.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents a class inheritance relationship
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct InheritanceRelation {
6    /// Name of the child class
7    pub child: String,
8
9    /// Name of the parent class
10    pub parent: String,
11
12    /// Line number where inheritance is declared
13    pub line: usize,
14}
15
16impl InheritanceRelation {
17    /// Create a new inheritance relation
18    pub fn new(child: impl Into<String>, parent: impl Into<String>, line: usize) -> Self {
19        Self {
20            child: child.into(),
21            parent: parent.into(),
22            line,
23        }
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    fn test_inheritance_relation_new() {
33        let inheritance = InheritanceRelation::new("Dog", "Animal", 5);
34        assert_eq!(inheritance.child, "Dog");
35        assert_eq!(inheritance.parent, "Animal");
36        assert_eq!(inheritance.line, 5);
37    }
38}