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

Function test_rust_struct_and_fields

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

Source from the content-addressed store, hash-verified

77
78#[test]
79fn test_rust_struct_and_fields() {
80 let source = r#"
81pub struct Point {
82 pub x: f64,
83 pub y: f64,
84 label: String,
85}
86"#;
87 let extractor = RustExtractor;
88 let result = extractor.extract("types.rs", source);
89 assert!(result.errors.is_empty(), "errors: {:?}", result.errors);
90 let structs: Vec<_> = result
91 .nodes
92 .iter()
93 .filter(|n| n.kind == NodeKind::Struct)
94 .collect();
95 assert_eq!(structs.len(), 1);
96 assert_eq!(structs[0].name, "Point");
97 assert_eq!(structs[0].visibility, Visibility::Pub);
98
99 let fields: Vec<_> = result
100 .nodes
101 .iter()
102 .filter(|n| n.kind == NodeKind::Field)
103 .collect();
104 assert_eq!(
105 fields.len(),
106 3,
107 "expected 3 fields, got: {:?}",
108 fields.iter().map(|n| &n.name).collect::<Vec<_>>()
109 );
110 assert!(fields
111 .iter()
112 .any(|f| f.name == "x" && f.visibility == Visibility::Pub));
113 assert!(fields
114 .iter()
115 .any(|f| f.name == "label" && f.visibility == Visibility::Private));
116}
117
118#[test]
119fn test_rust_enum_and_variants() {

Callers

nothing calls this directly

Calls 2

collectMethod · 0.80
extractMethod · 0.45

Tested by

no test coverage detected