codegraph_csharp/
lib.rs

1//! C# parser for CodeGraph
2//!
3//! This crate provides C# source code parsing capabilities, extracting
4//! code entities and their relationships for building code graphs.
5
6mod extractor;
7mod mapper;
8mod parser_impl;
9mod visitor;
10
11pub use parser_impl::CSharpParser;
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16    use codegraph::CodeGraph;
17    use codegraph_parser_api::CodeParser;
18    use std::path::Path;
19
20    #[test]
21    fn test_parser_creation() {
22        let parser = CSharpParser::new();
23        assert_eq!(parser.language(), "csharp");
24    }
25
26    #[test]
27    fn test_parse_simple_source() {
28        let parser = CSharpParser::new();
29        let mut graph = CodeGraph::in_memory().unwrap();
30
31        let source = r#"
32public class Calculator
33{
34    public int Add(int a, int b)
35    {
36        return a + b;
37    }
38}
39"#;
40
41        let result = parser.parse_source(source, Path::new("Calculator.cs"), &mut graph);
42        assert!(result.is_ok());
43
44        let file_info = result.unwrap();
45        assert_eq!(file_info.classes.len(), 1);
46        // Verify the class node exists in the graph
47        let class_node = graph.get_node(file_info.classes[0]).unwrap();
48        assert_eq!(
49            class_node.properties.get("name"),
50            Some(&codegraph::PropertyValue::String("Calculator".to_string()))
51        );
52    }
53}