Skip to content

Commit 1281198

Browse files
committed
Update tests
1 parent 1fce485 commit 1281198

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,9 @@ ConverterRefCount::MaterializeTemp(const std::string &binding_name,
500500
std::string binding;
501501
if (pointee->isConstantArrayType()) {
502502
PushConversionKind push(*this, ConversionKind::FullRefCount);
503-
binding = std::format("{} {} : {} = {};", decl, binding_name,
504-
ToString(pointee),
505-
BoxValue(ConvertVarInitValue(pointee, expr)));
503+
binding =
504+
std::format("{} {} : {} = {};", decl, binding_name, ToString(pointee),
505+
BoxValue(ConvertVarInitValue(pointee, expr)));
506506
} else {
507507
auto value = ConvertFreshRValue(expr, pointee);
508508
auto type_str = ToStringBase(pointee);

‎tests/unit/out/refcount/array_reference.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ fn main_0() -> i32 {
9999
assert!((({ len_0(buf.as_pointer(),) }) == 4));
100100
let arr: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([1, 2, 3])));
101101
assert!((({ sum_2(arr.as_pointer(),) }) == 6));
102+
assert!(
103+
(({
104+
let _a: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([1, 2, 3])));
105+
sum_2(_a.as_pointer())
106+
}) == 6)
107+
);
102108
({ fill_3(arr.as_pointer(), 7) });
103109
assert!((({ sum_2(arr.as_pointer(),) }) == 21));
104110
assert!((({ sum_twice_4(arr.as_pointer(),) }) == 42));
@@ -130,6 +136,25 @@ fn main_0() -> i32 {
130136
Ptr::<i8>::from_string_literal(b"cde"),
131137
])));
132138
assert!((({ total_len_13(names.as_pointer(),) }) == 5));
139+
let rows: Value<Box<[Value<Box<[i32]>>]>> = Rc::new(RefCell::new(Box::new([
140+
Rc::new(RefCell::new(Box::new([1, 2, 3]))),
141+
Rc::new(RefCell::new(Box::new([4, 5, 6]))),
142+
])));
143+
let mut p: Ptr<Value<Box<[i32]>>> = (rows.as_pointer() as Ptr<Value<Box<[i32]>>>);
144+
p.prefix_inc();
145+
assert!(
146+
({ (p.read().as_pointer()) } == {
147+
((((rows.as_pointer() as Ptr<Value<Box<[i32]>>>)
148+
.offset(1)
149+
.read()
150+
.as_pointer()) as Ptr<i32>)
151+
.offset(0))
152+
})
153+
);
154+
let r: Ptr<i32> = (p.read().as_pointer());
155+
assert!(((elem!((r), 0).read()) == 4));
156+
assert!((({ sum_2((r).clone(),) }) == 15));
157+
assert!((({ sum_2((p.read().as_pointer()),) }) == 15));
133158
return 0;
134159
}
135160
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/array_reference.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ unsafe fn main_0() -> i32 {
8686
assert!(((unsafe { len_0(&buf,) }) == (4)));
8787
let mut arr: [i32; 3] = [1, 2, 3];
8888
assert!(((unsafe { sum_2(&arr,) }) == (6)));
89+
assert!(
90+
((unsafe {
91+
let mut _a: [i32; 3] = [1, 2, 3];
92+
sum_2(&mut _a)
93+
}) == (6))
94+
);
8995
(unsafe { fill_3(&mut arr, 7) });
9096
assert!(((unsafe { sum_2(&arr,) }) == (21)));
9197
assert!(((unsafe { sum_twice_4(&arr,) }) == (42)));
@@ -111,6 +117,14 @@ unsafe fn main_0() -> i32 {
111117
assert!(((arr[(0) as usize]) == (3)));
112118
let mut names: [*const libc::c_char; 2] = [c"ab".as_ptr(), c"cde".as_ptr()];
113119
assert!(((unsafe { total_len_13(&mut names,) }) == (5)));
120+
let mut rows: [[i32; 3]; 2] = [[1, 2, 3], [4, 5, 6]];
121+
let mut p: *mut [i32; 3] = rows.as_mut_ptr();
122+
p.prefix_inc();
123+
assert!((((*p).as_mut_ptr()) == (&mut rows[(1) as usize][(0) as usize] as *mut i32)));
124+
let r: *mut [i32; 3] = &mut (*p);
125+
assert!((((*r)[(0) as usize]) == (4)));
126+
assert!(((unsafe { sum_2(r,) }) == (15)));
127+
assert!(((unsafe { sum_2(&(*p),) }) == (15)));
114128
return 0;
115129
}
116130
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)