| 734 | |
| 735 | #[test] |
| 736 | fn test_extract_struct() { |
| 737 | let mut parser = SwiftParser::new(); |
| 738 | let source = r#" |
| 739 | struct Point { |
| 740 | var x: Double |
| 741 | var y: Double |
| 742 | |
| 743 | func distance(to other: Point) -> Double { |
| 744 | let dx = x - other.x |
| 745 | let dy = y - other.y |
| 746 | return (dx * dx + dy * dy).squareRoot() |
| 747 | } |
| 748 | } |
| 749 | "#; |
| 750 | let entities = parser.extract(source, "geometry.swift"); |
| 751 | |
| 752 | let point = entities |
| 753 | .iter() |
| 754 | .find(|e| e.name == "Point") |
| 755 | .expect("Should find Point"); |
| 756 | assert_eq!(point.kind, EntityKind::Class); // Structs map to Class |
| 757 | assert!( |
| 758 | point.signature.as_ref().unwrap().contains("struct Point"), |
| 759 | "Signature should say 'struct': {:?}", |
| 760 | point.signature |
| 761 | ); |
| 762 | |
| 763 | let distance = entities.iter().find(|e| e.name == "distance"); |
| 764 | assert!(distance.is_some(), "Should find distance method"); |
| 765 | assert_eq!(distance.unwrap().kind, EntityKind::Method); |
| 766 | } |
| 767 | |
| 768 | #[test] |
| 769 | fn test_extract_enum() { |