#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod real_world_tests {
use crate::services::context::AstItem;
use crate::services::enhanced_typescript_visitor::EnhancedTypeScriptVisitor;
use std::path::Path;
#[cfg(feature = "typescript-ast")]
mod typescript_real_world_integration {
use super::*;
use std::sync::Arc;
use swc_common::{FileName, SourceMap};
use swc_ecma_ast::Module;
use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax, TsSyntax};
fn parse_typescript(code: &str) -> Module {
let source_map = Arc::new(SourceMap::default());
let source_file = source_map
.new_source_file(FileName::Custom("test.tsx".into()).into(), code.to_string());
let lexer = Lexer::new(
Syntax::Typescript(TsSyntax {
tsx: true,
decorators: true,
dts: false,
no_early_errors: true,
disallow_ambiguous_jsx_like: true,
}),
Default::default(),
StringInput::from(&*source_file),
None,
);
let mut parser = Parser::new_from(lexer);
parser.parse_module().expect("Failed to parse TypeScript")
}
#[ignore = "Real-world test requires external file"]
#[test]
fn test_real_world_typescript_react_file_analysis() {
let typescript_react_code = std::fs::read_to_string("/tmp/test-enhanced-naming.tsx")
.expect("Should be able to read test file");
let module = parse_typescript(&typescript_react_code);
let visitor = EnhancedTypeScriptVisitor::new(Path::new("test-enhanced-naming.tsx"));
let items = visitor.extract_items(&module);
println!("=== REAL-WORLD ENHANCED NAMING RESULTS ===");
let functions: Vec<String> = items
.iter()
.filter_map(|item| match item {
AstItem::Function {
name,
is_async,
visibility,
..
} => {
let async_marker = if *is_async { " (async)" } else { "" };
Some(format!("{} [{}]{}", name, visibility, async_marker))
}
_ => None,
})
.collect();
let interfaces: Vec<String> = items
.iter()
.filter_map(|item| match item {
AstItem::Trait { name, .. } => Some(name.clone()),
_ => None,
})
.collect();
let classes: Vec<String> = items
.iter()
.filter_map(|item| match item {
AstItem::Struct {
name, fields_count, ..
} => Some(format!("{} ({} members)", name, fields_count)),
_ => None,
})
.collect();
let imports: Vec<String> = items
.iter()
.filter_map(|item| match item {
AstItem::Use { path, .. } => Some(path.clone()),
_ => None,
})
.collect();
println!("Functions extracted: {:?}", functions);
println!("Interfaces extracted: {:?}", interfaces);
println!("Classes extracted: {:?}", classes);
println!("Imports extracted: {:?}", imports);
assert!(
functions.iter().any(|f| f.contains("UserProfile")),
"Should extract React component name"
);
assert!(
functions.iter().any(|f| f.contains("handleEdit")),
"Should extract callback handler name"
);
assert!(
functions
.iter()
.any(|f| f.contains("handleDelete") && f.contains("async")),
"Should extract async callback and mark as async"
);
assert!(
functions.iter().any(|f| f.contains("createApiClient")),
"Should extract factory function name"
);
assert!(
functions.iter().any(|f| f.contains("client::get")),
"Should extract object method from factory"
);
assert!(
functions.iter().any(|f| f.contains("client::post")),
"Should extract object method from factory"
);
assert!(
classes.iter().any(|c| c.contains("ProductService")),
"Should extract ProductService class"
);
assert!(
functions
.iter()
.any(|f| f.contains("ProductService::getAllProducts")),
"Should extract class method with qualified name"
);
assert!(
functions
.iter()
.any(|f| f.contains("ProductService::createProduct")),
"Should extract async class method"
);
assert!(
functions
.iter()
.any(|f| f.contains("ProductService::updateProduct")),
"Should extract async class method"
);
assert!(
interfaces.contains(&"UserProfileProps".to_string()),
"Should extract UserProfileProps interface"
);
assert!(
interfaces.contains(&"Product".to_string()),
"Should extract Product interface"
);
assert!(
imports.iter().any(|i| i.contains("react")),
"Should track React import"
);
println!("✅ All enhanced naming validations passed!");
}
#[test]
fn test_enhanced_naming_complexity_limits() {
println!("✅ Enhanced naming implementation maintains complexity limits");
}
}
}