| 767 | |
| 768 | #[test] |
| 769 | fn test_extract_impl_block() { |
| 770 | let mut parser = RustParser::new(); |
| 771 | let source = r#" |
| 772 | impl User { |
| 773 | pub fn new(name: String) -> Self { |
| 774 | Self { name, email: None, age: 0 } |
| 775 | } |
| 776 | |
| 777 | pub fn greet(&self) -> String { |
| 778 | format!("Hello, {}!", self.name) |
| 779 | } |
| 780 | |
| 781 | fn private_helper(&self) -> bool { |
| 782 | true |
| 783 | } |
| 784 | } |
| 785 | "#; |
| 786 | let entities = parser.extract(source, "src/models.rs"); |
| 787 | |
| 788 | // Should find the impl block itself |
| 789 | assert!( |
| 790 | entities |
| 791 | .iter() |
| 792 | .any(|e| e.name == "User" && e.kind == EntityKind::Module), |
| 793 | "Should find User impl block, got: {:?}", |
| 794 | entities |
| 795 | .iter() |
| 796 | .map(|e| (&e.name, &e.kind)) |
| 797 | .collect::<Vec<_>>() |
| 798 | ); |
| 799 | |
| 800 | // Should find methods inside the impl |
| 801 | let new_fn = entities.iter().find(|e| e.name == "new"); |
| 802 | assert!(new_fn.is_some(), "Should find new() associated function"); |
| 803 | assert_eq!( |
| 804 | new_fn.unwrap().kind, |
| 805 | EntityKind::Function, |
| 806 | "new() without self should be Function" |
| 807 | ); |
| 808 | |
| 809 | let greet = entities.iter().find(|e| e.name == "greet"); |
| 810 | assert!(greet.is_some(), "Should find greet() method"); |
| 811 | assert_eq!( |
| 812 | greet.unwrap().kind, |
| 813 | EntityKind::Method, |
| 814 | "greet(&self) should be Method" |
| 815 | ); |
| 816 | } |
| 817 | |
| 818 | #[test] |
| 819 | fn test_extract_trait_impl() { |