Skip to content

Commit 31ee468

Browse files
committed
Update tests
1 parent 9c6c06c commit 31ee468

30 files changed

Lines changed: 285 additions & 132 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main_0() -> i32 {
2424
assert!((({ apply_1(5, None,) }) == 5));
2525
assert!((({ apply_1(5, Some(FnPtr::<fn(i32) -> i32>::null()),) }) == 5));
2626
assert!((({ apply_1(5, Some(FnPtr::<fn(i32) -> i32>::new(identity_0)),) }) == 5));
27-
let mut negate: FnPtr<fn(i32) -> i32> = FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
27+
let mut negate: FnPtr<fn(i32) -> i32> = FnPtr::<fn(i32) -> i32>::new(|mut x: i32| -> i32 {
2828
{
2929
return -x;
3030
}

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ pub fn apply_twice_6(fn_: FnPtr<fn(i32) -> i32>, mut x: i32) -> i32 {
3838
})
3939
.clone();
4040
}
41+
pub fn none_match_7(pred: FnPtr<fn(i32) -> bool>, mut a: i32, mut b: i32) -> bool {
42+
let pred: Value<FnPtr<fn(i32) -> bool>> = Rc::new(RefCell::new(pred));
43+
let neg_pred: Value<FnPtr<fn(i32) -> bool>> = Rc::new(RefCell::new(lambda!(
44+
{
45+
let pred: Ptr<FnPtr<fn(i32) -> bool>> = pred.as_pointer();
46+
},
47+
|mut x: i32| -> bool {
48+
return !({ (*pred.upgrade().deref()).call(x) });
49+
}
50+
)));
51+
return ({ (*neg_pred.borrow()).call(a) }) && ({ (*neg_pred.borrow()).call(b) });
52+
}
4153
pub fn main() {
4254
__cpp2rust_init_globals();
4355
std::process::exit(main_0());
@@ -48,15 +60,15 @@ fn main_0() -> i32 {
4860
{
4961
let factor: Value<i32> = Rc::new(RefCell::new((*factor.borrow())));
5062
},
51-
|x: i32| -> i32 {
63+
|mut x: i32| -> i32 {
5264
return (x * (*factor.borrow()));
5365
}
5466
)));
5567
assert!((({ apply_twice_6((*scale.borrow()).copy_from(), 4,) }) == 36));
5668
assert!(
5769
(({
5870
apply_int_0(
59-
FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
71+
FnPtr::<fn(i32) -> i32>::new(|mut x: i32| -> i32 {
6072
{
6173
return -x;
6274
}
@@ -70,10 +82,10 @@ fn main_0() -> i32 {
7082
{
7183
let factor: Value<i32> = Rc::new(RefCell::new((*factor.borrow())));
7284
},
73-
|x: i32| -> i32 {
85+
|mut x: i32| -> i32 {
7486
return (x * (*factor.borrow()));
7587
},
76-
|x: f64| -> f64 {
88+
|mut x: f64| -> f64 {
7789
return (x * ((*factor.borrow()) as f64));
7890
}
7991
)));
@@ -82,7 +94,7 @@ fn main_0() -> i32 {
8294
assert!(
8395
(({
8496
apply_int_2(
85-
lambda!(Generic, {}, |x: i32| -> i32 {
97+
lambda!(Generic, {}, |mut x: i32| -> i32 {
8698
return -x;
8799
}),
88100
9,
@@ -94,15 +106,24 @@ fn main_0() -> i32 {
94106
{
95107
let factor: Value<i32> = Rc::new(RefCell::new((*factor.borrow())));
96108
},
97-
|x: i32| -> i32 {
109+
|mut x: i32| -> i32 {
98110
return (x + (*factor.borrow()));
99111
},
100-
|x: f64| -> f64 {
112+
|mut x: f64| -> f64 {
101113
return (x + ((*factor.borrow()) as f64));
102114
}
103115
)));
104116
assert!((({ apply_int_3((*offset.borrow()).copy_from(), 4,) }) == 7));
105117
assert!((({ apply_double_5((*offset.borrow()).copy_from(), 1.5_f64,) }) == 4.5_f64));
118+
let is_even: Value<FnPtr<fn(i32) -> bool>> = Rc::new(RefCell::new(
119+
FnPtr::<fn(i32) -> bool>::new(|mut x: i32| -> bool {
120+
{
121+
return ((x % 2) == 0);
122+
}
123+
}),
124+
));
125+
assert!(({ none_match_7((*is_even.borrow()).copy_from(), 1, 3,) }));
126+
assert!(!({ none_match_7((*is_even.borrow()).copy_from(), 1, 4,) }));
106127
return 0;
107128
}
108129
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main_0() -> i32 {
1919
})));
2020
assert!((({ (*zero.borrow()).call() }) == 42));
2121
let one: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(FnPtr::<fn(i32) -> i32>::new(
22-
|x: i32| -> i32 {
22+
|mut x: i32| -> i32 {
2323
{
2424
return (x + 1);
2525
}
@@ -28,7 +28,7 @@ fn main_0() -> i32 {
2828
assert!((({ (*one.borrow()).call(1,) }) == 2));
2929
let three: Value<FnPtr<fn(i32, i32, i32) -> i32>> =
3030
Rc::new(RefCell::new(FnPtr::<fn(i32, i32, i32) -> i32>::new(
31-
|x: i32, y: i32, z: i32| -> i32 {
31+
|mut x: i32, mut y: i32, mut z: i32| -> i32 {
3232
{
3333
return (((x * 100) + (y * 10)) + z);
3434
}
@@ -38,7 +38,7 @@ fn main_0() -> i32 {
3838
let mut k: i32 = 3;
3939
let mut m: i32 = 4;
4040
let constants: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(
41-
FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
41+
FnPtr::<fn(i32) -> i32>::new(|mut x: i32| -> i32 {
4242
{
4343
return ((x + 3) + 4);
4444
}
@@ -47,21 +47,46 @@ fn main_0() -> i32 {
4747
assert!((({ (*constants.borrow()).call(1,) }) == 8));
4848
let mut n: i32 = (k + m);
4949
let derived: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(
50-
FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
50+
FnPtr::<fn(i32) -> i32>::new(|mut x: i32| -> i32 {
5151
{
5252
return (x + (3 + 4));
5353
}
5454
}),
5555
));
5656
assert!((({ (*derived.borrow()).call(1,) }) == 8));
5757
let implicit: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(
58-
FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
58+
FnPtr::<fn(i32) -> i32>::new(|mut x: i32| -> i32 {
5959
{
6060
return (x + 3);
6161
}
6262
}),
6363
));
6464
assert!((({ (*implicit.borrow()).call(1,) }) == 4));
65+
let bump: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(FnPtr::<fn(i32) -> i32>::new(
66+
|mut x: i32| -> i32 {
67+
{
68+
x += 1;
69+
return x;
70+
}
71+
},
72+
)));
73+
assert!((({ (*bump.borrow()).call(1,) }) == 2));
74+
let through_ptr: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(
75+
FnPtr::<fn(i32) -> i32>::new(|x: i32| -> i32 {
76+
{
77+
let x: Value<i32> = Rc::new(RefCell::new(x));
78+
let mut p: Ptr<i32> = (x.as_pointer());
79+
p.write({ ((p.read()) * 2) });
80+
return (*x.borrow());
81+
}
82+
}),
83+
));
84+
assert!((({ (*through_ptr.borrow()).call(4,) }) == 8));
85+
let mut seed: i32 = 5;
86+
let boxed: Value<i32> = Rc::new(RefCell::new(({ (*through_ptr.borrow()).call(seed) })));
87+
let mut boxed_ptr: Ptr<i32> = (boxed.as_pointer());
88+
assert!(((boxed_ptr.read()) == 10));
89+
assert!((seed == 5));
6590
return 0;
6691
}
6792
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main_0() -> i32 {
2020
let b: Value<i32> = Rc::new(RefCell::new((*b.borrow())));
2121
let c: Value<i32> = Rc::new(RefCell::new((*c.borrow())));
2222
},
23-
|x: i32| -> i32 {
23+
|mut x: i32| -> i32 {
2424
return ((((*a.borrow()) + (*b.borrow())) + (*c.borrow())) + x);
2525
}
2626
)));
@@ -33,7 +33,7 @@ fn main_0() -> i32 {
3333
let b: Ptr<i32> = b.as_pointer();
3434
let c: Ptr<i32> = c.as_pointer();
3535
},
36-
|x: i32| -> i32 {
36+
|mut x: i32| -> i32 {
3737
return ((((a.read()) + (b.read())) + (c.read())) + x);
3838
}
3939
)));
@@ -46,7 +46,7 @@ fn main_0() -> i32 {
4646
let a: Value<i32> = Rc::new(RefCell::new((*a.borrow())));
4747
let b: Value<i32> = Rc::new(RefCell::new((*b.borrow())));
4848
},
49-
|x: i32| -> i32 {
49+
|mut x: i32| -> i32 {
5050
{
5151
let __rhs = x;
5252
c.with_mut(|__v| *__v = *__v + __rhs)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main_0() -> i32 {
2424
{
2525
let base: Ptr<i32> = base.as_pointer();
2626
},
27-
|x: i32| -> i32 {
27+
|mut x: i32| -> i32 {
2828
return (x + (base.read()));
2929
}
3030
)));
@@ -60,7 +60,7 @@ fn main_0() -> i32 {
6060
{
6161
let arr: Ptr<u16> = arr.as_pointer();
6262
},
63-
|i: usize, j: usize| {
63+
|mut i: usize, mut j: usize| {
6464
let mut t: u16 = (elem!((arr), j).read());
6565
elem!((arr), j).write({ (elem!((arr), i).read()) });
6666
elem!((arr), i).write(t);
@@ -74,7 +74,7 @@ fn main_0() -> i32 {
7474
{
7575
let t: Ptr<i32> = total.as_pointer();
7676
},
77-
|x: i32| {
77+
|mut x: i32| {
7878
{
7979
let __rhs = { x };
8080
t.with_mut(|__v| *__v = *__v + __rhs)
@@ -88,7 +88,7 @@ fn main_0() -> i32 {
8888
{
8989
let y: Ptr<i32> = field_ptr!(s.as_pointer(), y);
9090
},
91-
|v: i32| {
91+
|mut v: i32| {
9292
y.write({ v });
9393
}
9494
)));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl SImpl for Ptr<S> {
4949
{
5050
let this_: Value<Ptr<S>> = Rc::new(RefCell::new((*self).clone()));
5151
},
52-
|k: i32| {
52+
|mut k: i32| {
5353
{
5454
let __rhs = k;
5555
field!((*this_.borrow()).clone(), n).with_mut(|__v| *__v = *__v + __rhs)
@@ -64,7 +64,7 @@ impl SImpl for Ptr<S> {
6464
{
6565
let this_: Value<Ptr<S>> = Rc::new(RefCell::new((*self).clone()));
6666
},
67-
|k: i32| {
67+
|mut k: i32| {
6868
({ SImpl::add(&(*this_.borrow()).clone(), k) });
6969
}
7070
)));

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main_0() -> i32 {
2727
{
2828
let factor: Value<i32> = Rc::new(RefCell::new((*factor.borrow())));
2929
},
30-
|x: i32| -> i32 {
30+
|mut x: i32| -> i32 {
3131
return (x * (*factor.borrow()));
3232
}
3333
)));
@@ -62,7 +62,7 @@ fn main_0() -> i32 {
6262
{
6363
let y: Value<i32> = Rc::new(RefCell::new((base + 1)));
6464
},
65-
|x: i32| -> i32 {
65+
|mut x: i32| -> i32 {
6666
return (x + (*y.borrow()));
6767
}
6868
)));
@@ -72,7 +72,7 @@ fn main_0() -> i32 {
7272
{
7373
let k: Value<i32> = Rc::new(RefCell::new((*k.borrow())));
7474
},
75-
|x: i32| -> i32 {
75+
|mut x: i32| -> i32 {
7676
return (x + 3);
7777
}
7878
)));
@@ -81,7 +81,7 @@ fn main_0() -> i32 {
8181
{
8282
let k: Value<i32> = Rc::new(RefCell::new((*k.borrow())));
8383
},
84-
|x: i32| -> i32 {
84+
|mut x: i32| -> i32 {
8585
return (x + ({ read_0(k.as_pointer()) }));
8686
}
8787
)));
@@ -90,7 +90,7 @@ fn main_0() -> i32 {
9090
{
9191
let k: Value<i32> = Rc::new(RefCell::new((*k.borrow())));
9292
},
93-
|x: i32| -> i32 {
93+
|mut x: i32| -> i32 {
9494
return (x + ({ read_0(k.as_pointer()) }));
9595
}
9696
)));
@@ -99,7 +99,7 @@ fn main_0() -> i32 {
9999
{
100100
let k: Ptr<i32> = k.as_pointer();
101101
},
102-
|x: i32| -> i32 {
102+
|mut x: i32| -> i32 {
103103
return (x + 3);
104104
}
105105
)));

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ fn main_0() -> i32 {
1414
let twice: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(
1515
Generic,
1616
{},
17-
|x: i32| -> i32 {
17+
|mut x: i32| -> i32 {
1818
return (x + x);
1919
},
20-
|x: f64| -> f64 {
20+
|mut x: f64| -> f64 {
2121
return (x + x);
2222
}
2323
)));
@@ -29,10 +29,10 @@ fn main_0() -> i32 {
2929
{
3030
let base: Value<i32> = Rc::new(RefCell::new((*base.borrow())));
3131
},
32-
|x: i32| -> i32 {
32+
|mut x: i32| -> i32 {
3333
return (x + (*base.borrow()));
3434
},
35-
|x: f64| -> f64 {
35+
|mut x: f64| -> f64 {
3636
return (x + ((*base.borrow()) as f64));
3737
}
3838
)));
@@ -48,13 +48,13 @@ fn main_0() -> i32 {
4848
{
4949
let total: Ptr<i32> = total.as_pointer();
5050
},
51-
|x: i32, y: i32| {
51+
|mut x: i32, mut y: i32| {
5252
{
5353
let __rhs = (x * y);
5454
total.with_mut(|__v| *__v = *__v + __rhs)
5555
};
5656
},
57-
|x: u32, y: u32| {
57+
|mut x: u32, mut y: u32| {
5858
total.write({ (((total.read()) as u32).wrapping_add((x).wrapping_mul(y))) as i32 });
5959
}
6060
)));
@@ -68,10 +68,10 @@ fn main_0() -> i32 {
6868
let sub: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(
6969
Generic,
7070
{},
71-
|x: i32, y: i32| -> i32 {
71+
|mut x: i32, mut y: i32| -> i32 {
7272
return (x - y);
7373
},
74-
|x: f64, y: f64| -> f64 {
74+
|mut x: f64, mut y: f64| -> f64 {
7575
return (x - y);
7676
}
7777
)));
@@ -88,10 +88,10 @@ fn main_0() -> i32 {
8888
{
8989
let base: Value<i32> = Rc::new(RefCell::new((*base.borrow())));
9090
},
91-
|x: i32, y: i32| -> i32 {
91+
|mut x: i32, mut y: i32| -> i32 {
9292
return ((x * y) + (*base.borrow()));
9393
},
94-
|x: i32, y: f64| -> f64 {
94+
|mut x: i32, mut y: f64| -> f64 {
9595
return (((x as f64) * y) + ((*base.borrow()) as f64));
9696
}
9797
)));
@@ -103,6 +103,21 @@ fn main_0() -> i32 {
103103
.call(2, 0.5_f64)
104104
}) == 11_f64)
105105
);
106+
let unused: Value<FnPtr<Generic>> = Rc::new(RefCell::new(lambda!(Generic, {})));
107+
&(*unused.borrow_mut());
108+
let outer: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(lambda!(
109+
{
110+
let base: Value<i32> = Rc::new(RefCell::new((*base.borrow())));
111+
},
112+
|mut y: i32| -> i32 {
113+
let inner: Value<FnPtr<Generic>> =
114+
Rc::new(RefCell::new(lambda!(Generic, {}, |mut z: i32| -> i32 {
115+
return (z + 1);
116+
})));
117+
return (({ (*inner.borrow()).spec::<fn(i32) -> i32>(0).call(y) }) + (*base.borrow()));
118+
}
119+
)));
120+
assert!((({ (*outer.borrow()).call(5,) }) == 16));
106121
return 0;
107122
}
108123
pub fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)