#![cfg_attr(coverage_nightly, coverage(off))]
use crate::models::unified_ast::AstDag;
use anyhow::Result;
use std::path::Path;
pub use super::ast_cpp_compat::{
analyze_cpp_file, analyze_cpp_file_with_classifier, analyze_cpp_file_with_complexity,
analyze_cpp_file_with_complexity_and_classifier,
};
pub struct CppAstParser {}
impl Default for CppAstParser {
fn default() -> Self {
Self::new()
}
}
impl CppAstParser {
#[must_use]
pub fn new() -> Self {
Self {}
}
pub fn parse_file(&mut self, _path: &Path, _content: &str) -> Result<AstDag> {
Err(anyhow::anyhow!(
"C++ AST parsing has been moved to the new AST module"
))
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[cfg(feature = "cpp-ast")]
fn test_parse_simple_cpp_class() {
let mut parser = CppAstParser::new();
let content = r#"
class MyClass {
public:
MyClass() {}
~MyClass() {}
void doSomething() const { }
private:
int value;
};
"#;
let result = parser.parse_file(Path::new("test.cpp"), content);
if let Ok(dag) = result {
assert!(!dag.nodes.is_empty());
}
}
#[test]
#[cfg(feature = "cpp-ast")]
fn test_parse_cpp_templates() {
let mut parser = CppAstParser::new();
let content = r#"
template<typename T>
class Vector {
T* data;
size_t size;
public:
Vector() : data(nullptr), size(0) {}
void push_back(const T& value) { }
};
"#;
let result = parser.parse_file(Path::new("test.cpp"), content);
let _ = result;
}
#[test]
#[cfg(feature = "cpp-ast")]
fn test_parse_cpp_lambdas() {
let mut parser = CppAstParser::new();
let content = r#"
void example() {
auto lambda = [](int x) -> int { return x * 2; };
auto result = lambda(5);
}
"#;
let result = parser.parse_file(Path::new("test.cpp"), content);
let _ = result;
}
#[test]
#[cfg(not(feature = "cpp-ast"))]
fn test_cpp_ast_disabled() {
let mut parser = CppAstParser::new();
let content = "class A {};";
let result = parser.parse_file(Path::new("test.cpp"), content);
assert!(result.is_err());
}
#[test]
fn test_compatibility_layer() {
let _parser = CppAstParser::new();
let _default_parser = CppAstParser::default();
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod property_tests {
use proptest::prelude::*;
proptest! {
#[test]
fn basic_property_stability(_input in ".*") {
prop_assert!(true);
}
#[test]
fn module_consistency_check(_x in 0u32..1000) {
prop_assert!(_x < 1001);
}
}
}