1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! DECY-136: C99 Flexible Array Members โ Vec
//!
//! C99 ยง6.7.2.1 Flexible array members allow structs to have a trailing
//! array of unspecified size:
//!
//! struct Buffer {
//! int size;
//! char data[]; // Flexible array member
//! };
//!
//! Expected Rust transformation:
//! - `char data[]` โ `data: Vec<u8>`
//! - `int values[]` โ `values: Vec<i32>`
use decy_core::transpile;
/// Test flexible array member transforms to Vec.
///
/// C: struct Buffer { int size; char data[]; };
/// Expected Rust: struct Buffer { size: i32, data: Vec<u8> }
#[test]
fn test_flexible_array_member_to_vec() {
let c_code = r#"
struct Buffer {
int size;
char data[];
};
int main() {
return 0;
}
"#;
let result = transpile(c_code).expect("Transpilation should succeed");
println!("Generated Rust code:\n{}", result);
// Should contain Buffer struct
assert!(
result.contains("pub struct Buffer"),
"Should have Buffer struct\nGenerated:\n{}",
result
);
// Should have data field as Vec<u8>
assert!(
result.contains("data: Vec<u8>") || result.contains("data: Vec<i8>"),
"Flexible array member should become Vec\nGenerated:\n{}",
result
);
}
/// Test flexible int array member transforms to Vec<i32>.
///
/// C: struct IntArray { int count; int values[]; };
/// Expected Rust: struct IntArray { count: i32, values: Vec<i32> }
#[test]
fn test_flexible_int_array_to_vec() {
let c_code = r#"
struct IntArray {
int count;
int values[];
};
int main() {
return 0;
}
"#;
let result = transpile(c_code).expect("Transpilation should succeed");
println!("Generated Rust code:\n{}", result);
// Should have values field as Vec<i32>
assert!(
result.contains("values: Vec<i32>"),
"Flexible int array should become Vec<i32>\nGenerated:\n{}",
result
);
}