Skip to content

Commit bb764c8

Browse files
committed
Update tests
1 parent 7ca511e commit bb764c8

4 files changed

Lines changed: 116 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ fn main_0() -> i32 {
5050
}),
5151
));
5252
assert!((({ (*constants.borrow()).call(1,) }) == 8));
53+
let n: Value<i32> = Rc::new(RefCell::new(((*k.borrow()) + (*m.borrow()))));
54+
let derived: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(
55+
FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
56+
{
57+
let x: Value<i32> = Rc::new(RefCell::new(x));
58+
return ((*x.borrow()) + (3 + 4));
59+
}
60+
}),
61+
));
62+
assert!((({ (*derived.borrow()).call(1,) }) == 8));
63+
let implicit: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(
64+
FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
65+
{
66+
let x: Value<i32> = Rc::new(RefCell::new(x));
67+
return ((*x.borrow()) + 3);
68+
}
69+
}),
70+
));
71+
assert!((({ (*implicit.borrow()).call(1,) }) == 4));
5372
return 0;
5473
}
5574
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub struct S {
1414
#[offset(4)]
1515
pub y: i32,
1616
}
17+
pub fn read_0(v: Ptr<i32>) -> i32 {
18+
return (v.read());
19+
}
1720
pub fn main() {
1821
__cpp2rust_init_globals();
1922
std::process::exit(main_0());
@@ -66,6 +69,47 @@ fn main_0() -> i32 {
6669
}
6770
)));
6871
assert!((({ (*shifted.borrow()).call(5,) }) == 16));
72+
let k: Value<i32> = Rc::new(RefCell::new(3));
73+
let by_copy: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(lambda!(
74+
{
75+
let k: Value<i32> = Rc::new(RefCell::new((*k.borrow())));
76+
},
77+
|x: i32| -> i32 {
78+
let x: Value<i32> = Rc::new(RefCell::new(x));
79+
return ((*x.borrow()) + 3);
80+
}
81+
)));
82+
assert!((({ (*by_copy.borrow()).call(1,) }) == 4));
83+
let by_copy_used: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(lambda!(
84+
{
85+
let k: Value<i32> = Rc::new(RefCell::new((*k.borrow())));
86+
},
87+
|x: i32| -> i32 {
88+
let x: Value<i32> = Rc::new(RefCell::new(x));
89+
return ((*x.borrow()) + ({ read_0(k.as_pointer()) }));
90+
}
91+
)));
92+
assert!((({ (*by_copy_used.borrow()).call(1,) }) == 4));
93+
let implicit_used: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(lambda!(
94+
{
95+
let k: Value<i32> = Rc::new(RefCell::new((*k.borrow())));
96+
},
97+
|x: i32| -> i32 {
98+
let x: Value<i32> = Rc::new(RefCell::new(x));
99+
return ((*x.borrow()) + ({ read_0(k.as_pointer()) }));
100+
}
101+
)));
102+
assert!((({ (*implicit_used.borrow()).call(1,) }) == 4));
103+
let by_ref: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(lambda!(
104+
{
105+
let k: Ptr<i32> = k.as_pointer();
106+
},
107+
|x: i32| -> i32 {
108+
let x: Value<i32> = Rc::new(RefCell::new(x));
109+
return ((*x.borrow()) + 3);
110+
}
111+
)));
112+
assert!((({ (*by_ref.borrow()).call(1,) }) == 4));
69113
return 0;
70114
}
71115
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ unsafe fn main_0() -> i32 {
4040
}
4141
});
4242
assert!(((unsafe { constants.call(1,) }) == (8)));
43+
let n: i32 = ((k) + (m));
44+
let mut derived: FnPtr<fn(i32) -> i32> = FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
45+
unsafe {
46+
return ((x) + ((3) + (4)));
47+
}
48+
});
49+
assert!(((unsafe { derived.call(1,) }) == (8)));
50+
let mut implicit: FnPtr<fn(i32) -> i32> = FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
51+
unsafe {
52+
return ((x) + (3));
53+
}
54+
});
55+
assert!(((unsafe { implicit.call(1,) }) == (4)));
4356
return 0;
4457
}
4558
pub unsafe fn __cpp2rust_init_globals() {}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub struct S {
1212
pub x: i32,
1313
pub y: i32,
1414
}
15+
pub unsafe fn read_0(v: *const i32) -> i32 {
16+
return (*v);
17+
}
1518
pub fn main() {
1619
unsafe {
1720
__cpp2rust_init_globals();
@@ -64,6 +67,43 @@ unsafe fn main_0() -> i32 {
6467
}
6568
);
6669
assert!(((unsafe { shifted.call(5,) }) == (16)));
70+
let k: i32 = 3;
71+
let mut by_copy: FnPtr<fn(i32) -> i32> = lambda_unsafe!(
72+
{
73+
let k: i32 = k;
74+
},
75+
|x: i32| -> i32 {
76+
return ((x) + (3));
77+
}
78+
);
79+
assert!(((unsafe { by_copy.call(1,) }) == (4)));
80+
let mut by_copy_used: FnPtr<fn(i32) -> i32> = lambda_unsafe!(
81+
{
82+
let k: i32 = k;
83+
},
84+
|x: i32| -> i32 {
85+
return ((x) + (unsafe { read_0(&k) }));
86+
}
87+
);
88+
assert!(((unsafe { by_copy_used.call(1,) }) == (4)));
89+
let mut implicit_used: FnPtr<fn(i32) -> i32> = lambda_unsafe!(
90+
{
91+
let k: i32 = k;
92+
},
93+
|x: i32| -> i32 {
94+
return ((x) + (unsafe { read_0(&k) }));
95+
}
96+
);
97+
assert!(((unsafe { implicit_used.call(1,) }) == (4)));
98+
let mut by_ref: FnPtr<fn(i32) -> i32> = lambda_unsafe!(
99+
{
100+
let k: *const i32 = &k;
101+
},
102+
|x: i32| -> i32 {
103+
return ((x) + (3));
104+
}
105+
);
106+
assert!(((unsafe { by_ref.call(1,) }) == (4)));
67107
return 0;
68108
}
69109
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)