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

Function test_rust_function

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

Source from the content-addressed store, hash-verified

19
20#[test]
21fn test_rust_function() {
22 let source = r#"
23/// Adds two numbers.
24pub fn add(a: i32, b: i32) -> i32 {
25 a + b
26}
27
28fn helper() {}
29"#;
30 let extractor = RustExtractor;
31 let result = extractor.extract("math.rs", source);
32 assert!(result.errors.is_empty(), "errors: {:?}", result.errors);
33 let fns: Vec<_> = result
34 .nodes
35 .iter()
36 .filter(|n| n.kind == NodeKind::Function)
37 .collect();
38 assert_eq!(
39 fns.len(),
40 2,
41 "expected 2 functions, got: {:?}",
42 fns.iter().map(|n| &n.name).collect::<Vec<_>>()
43 );
44 let add_fn = fns.iter().find(|f| f.name == "add").expect("add not found");
45 assert_eq!(add_fn.visibility, Visibility::Pub);
46 assert!(add_fn
47 .docstring
48 .as_deref()
49 .unwrap_or("")
50 .contains("Adds two numbers"));
51 assert!(add_fn.signature.as_deref().unwrap_or("").contains("fn add"));
52 let helper = fns
53 .iter()
54 .find(|f| f.name == "helper")
55 .expect("helper not found");
56 assert_eq!(helper.visibility, Visibility::Private);
57}
58
59#[test]
60fn test_rust_async_function() {

Callers

nothing calls this directly

Calls 2

collectMethod · 0.80
extractMethod · 0.45

Tested by

no test coverage detected