MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / test_rust_impl_block

Function test_rust_impl_block

tests/extraction_suite/rust.rs:179–217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

177
178#[test]
179fn test_rust_impl_block() {
180 let source = r#"
181struct Rect { w: f64, h: f64 }
182
183impl 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]
220fn test_rust_use_declarations() {

Callers

nothing calls this directly

Calls 2

collectMethod · 0.80
extractMethod · 0.45

Tested by

no test coverage detected