Skip to content

Commit 9a709c7

Browse files
committed
Update tests
1 parent a1917e6 commit 9a709c7

6 files changed

Lines changed: 35 additions & 13 deletions

File tree

‎rules/pair/src.cpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
template <typename T1, typename T2> using t1 = std::pair<T1, T2>;
77

8-
template <typename T1, typename T2> using t2 = std::pair<const T1, T2>;
9-
108
template <typename T1, typename T2> T2 &f1(std::pair<T1, T2> &o) {
119
return o.second;
1210
}

‎rules/pair/tgt_refcount.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ fn t1<T1: Default, T2: Default>() -> (Value<T1>, Value<T2>) {
1212
)
1313
}
1414

15-
fn t2<T1: Default, T2: Default>() -> (Value<T1>, Value<T2>) {
16-
(
17-
Rc::new(RefCell::new(T1::default())),
18-
Rc::new(RefCell::new(T2::default())),
19-
)
20-
}
21-
2215
fn f1<T1, T2>(a0: (Value<T1>, Value<T2>)) -> Value<T2> {
2316
a0.1
2417
}

‎rules/pair/tgt_unsafe.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ fn t1<T1: Default, T2: Default>() -> (T1, T2) {
55
<(T1, T2)>::default()
66
}
77

8-
fn t2<T1: Default, T2: Default>() -> (T1, T2) {
9-
<(T1, T2)>::default()
10-
}
11-
128
unsafe fn f1<T1, T2>(a0: (T1, T2)) -> T2 {
139
a0.1
1410
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ fn main_0() -> i32 {
2929
)));
3030
assert!(((*(*p3.borrow()).0.borrow()) == 5_f64));
3131
assert!(((*(*p3.borrow()).1.borrow()) == 6));
32+
let arr: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([1, 2])));
33+
let mut n: u32 = 2_u32;
34+
let const_ptr_pairs: Value<Vec<(Value<Ptr<i32>>, Value<u64>)>> = Rc::new(RefCell::new(
35+
(0..(1_usize) as usize)
36+
.map(|_| <(Value<Ptr<i32>>, Value<u64>)>::default())
37+
.collect::<Vec<_>>(),
38+
));
39+
(*const_ptr_pairs.borrow_mut())[0_usize] = (
40+
Rc::new(RefCell::new(
41+
(arr.as_pointer() as Ptr<i32>)
42+
.offset((1) as isize)
43+
.try_into()
44+
.expect("failed conversion"),
45+
)),
46+
Rc::new(RefCell::new(n.try_into().expect("failed conversion"))),
47+
);
48+
assert!(
49+
(((*(*const_ptr_pairs.borrow())[0_usize].0.borrow()).read()) == 2)
50+
&& ((*(*const_ptr_pairs.borrow())[0_usize].1.borrow()) == 2_u64)
51+
);
3252
return 0;
3353
}
3454
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ unsafe fn main_0() -> i32 {
2222
let mut p3: (f64, i32) = (5.into(), 6.into());
2323
assert!(((p3.0) == (5_f64)));
2424
assert!(((p3.1) == (6)));
25+
let arr: [i32; 2] = [1, 2];
26+
let mut n: u32 = 2_u32;
27+
let mut const_ptr_pairs: Vec<(*const i32, u64)> = (0..(1_usize) as usize)
28+
.map(|_| <(*const i32, u64)>::default())
29+
.collect::<Vec<_>>();
30+
const_ptr_pairs[(0_usize)] = (arr.as_ptr().offset((1) as isize).into(), n.into());
31+
assert!(
32+
((*const_ptr_pairs[(0_usize)].0) == (2)) && ((const_ptr_pairs[(0_usize)].1) == (2_u64))
33+
);
2534
return 0;
2635
}
2736
pub unsafe fn __cpp2rust_init_globals() {}

‎tests/unit/pair.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <assert.h>
22
#include <utility>
3+
#include <vector>
34

45
int main() {
56
std::pair<double, int> p1(1, 2);
@@ -11,5 +12,10 @@ int main() {
1112
std::pair<double, int> p3 = std::make_pair(5, 6);
1213
assert(p3.first == 5.0);
1314
assert(p3.second == 6);
15+
const int arr[2] = {1, 2};
16+
unsigned n = 2;
17+
std::vector<std::pair<const int *, size_t>> const_ptr_pairs(1);
18+
const_ptr_pairs[0] = std::make_pair(arr + 1, n);
19+
assert(*const_ptr_pairs[0].first == 2 && const_ptr_pairs[0].second == 2);
1420
return 0;
1521
}

0 commit comments

Comments
 (0)