| 177 | |
| 178 | #[test] |
| 179 | fn test_rust_impl_block() { |
| 180 | let source = r#" |
| 181 | struct Rect { w: f64, h: f64 } |
| 182 | |
| 183 | impl Rect { |
| 184 | pub fn new(w: f64, h: f64) -> Self { |
| 185 | Rect { w, h } |
| 186 | } |
| 187 | |
| 188 | pub fn area(&self) -> f64 { |
| 189 | self.w * self.h |
| 190 | } |
| 191 | } |
| 192 | "#; |
| 193 | let extractor = RustExtractor; |
| 194 | let result = extractor.extract("rect.rs", source); |
| 195 | assert!(result.errors.is_empty(), "errors: {:?}", result.errors); |
| 196 | let impls: Vec<_> = result |
| 197 | .nodes |
| 198 | .iter() |
| 199 | .filter(|n| n.kind == NodeKind::Impl) |
| 200 | .collect(); |
| 201 | assert_eq!(impls.len(), 1); |
| 202 | let methods: Vec<_> = result |
| 203 | .nodes |
| 204 | .iter() |
| 205 | .filter(|n| n.kind == NodeKind::Method) |
| 206 | .collect(); |
| 207 | assert_eq!( |
| 208 | methods.len(), |
| 209 | 2, |
| 210 | "methods: {:?}", |
| 211 | methods.iter().map(|n| &n.name).collect::<Vec<_>>() |
| 212 | ); |
| 213 | assert!(methods.iter().any(|m| m.name == "new")); |
| 214 | assert!(methods.iter().any(|m| m.name == "area")); |
| 215 | // Contains edges from impl to methods |
| 216 | assert!(result.edges.iter().any(|e| e.kind == EdgeKind::Contains)); |
| 217 | } |
| 218 | |
| 219 | #[test] |
| 220 | fn test_rust_use_declarations() { |