use syn::visit::Visit;
use crate::rudi::difactroy::ruast::{ru_ast, RuAst};
#[cfg(test)]
mod tests {
use super::*;
#[allow(dead_code)]
fn getCode() -> &'static str {
r#"
trait BaseEntity { fn id(&self) -> u64; }
trait BaseEntitySingle { fn id(&self) -> u64; }
struct User { id: u64 }
struct Order { id: u64 }
impl BaseEntity for User {
fn id(&self) -> u64 { self.id }
}
impl BaseEntitySingle for User {
fn id(&self) -> u64 { self.id }
}
// 这个不是 BaseEntity
impl Clone for Order {
fn clone(&self) -> Self { todo!() }
}
mod inner {
use super::BaseEntity;
struct Admin;
impl BaseEntity for Admin {
fn id(&self) -> u64 { 0 }
}
}
"#
}
#[test]
fn find_01_base_entity() {
let ast = RuAst::parse_file_content(getCode()).expect("parse failed");
let ra = RuAst::new();
let found = ra.find_base_entity(&ast);
println!("简单遍历找到: {:?}", found);
let mut visitor = ru_ast::BaseEntityImplVisitor { results: vec![] };
visitor.visit_file(&ast);
println!("Visitor 找到: {:?}", visitor.results); let mut found1 = ra.find_base_entity(&ast);
println!("简单遍历找到:baseentity {:?}", found);
let found2 = ra.find_base_entity_single(&ast);
println!("简单遍历找到: baseentitysngle{:?}", found);
found1.extend(found2);
println!("简单遍历找到: baseentitysngle-all{:?}", found1);
}
#[test]
fn find_02_parse_file_content() {
let ast = RuAst::parse_file_content(getCode()).expect("parse failed");
let ra = RuAst::new();
let found = ra.find_base_entity_all(&ast);
println!("简单遍历找到: {:?}", found);
}
#[test]
fn find_03_parse_file_content() {
let ast = RuAst::parse_file_content(getCode()).expect("parse failed");
let ra = RuAst::new();
let found = ra.find_base_entity_all(&ast);
println!("简单遍历找到: {:?}", found);
}
}