Skip to content

Commit 7897e0b

Browse files
committed
Update tests
1 parent fe23efa commit 7897e0b

19 files changed

Lines changed: 90 additions & 71 deletions

‎tests/unit/lambda_basic.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ int main() {
1515
auto constants = [](int x) { return x + k + m; };
1616
assert(constants(1) == 8);
1717

18+
const int n = k + m;
19+
auto derived = [](int x) { return x + n; };
20+
assert(derived(1) == 8);
21+
22+
auto implicit = [=](int x) { return x + k; };
23+
assert(implicit(1) == 4);
24+
1825
return 0;
1926
}

‎tests/unit/lambda_capture_value.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ struct S {
55
int y;
66
};
77

8+
int read(const int &v) { return v; }
9+
810
int main() {
911
int factor = 3;
1012
auto scale = [factor](int x) { return x * factor; };
@@ -27,5 +29,18 @@ int main() {
2729
auto shifted = [y = base + 1](int x) { return x + y; };
2830
assert(shifted(5) == 16);
2931

32+
const int k = 3;
33+
auto by_copy = [k](int x) { return x + k; };
34+
assert(by_copy(1) == 4);
35+
36+
auto by_copy_used = [k](int x) { return x + read(k); };
37+
assert(by_copy_used(1) == 4);
38+
39+
auto implicit_used = [=](int x) { return x + read(k); };
40+
assert(implicit_used(1) == 4);
41+
42+
auto by_ref = [&k](int x) { return x + k; };
43+
assert(by_ref(1) == 4);
44+
3045
return 0;
3146
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn main_0() -> i32 {
9999
let c: Value<Counted> = Rc::new(RefCell::new(Counted::copy_from({ c.as_pointer() })));
100100
},
101101
|| -> i32 {
102-
return (({ (*self.c.borrow()).copies } * 10) + { (*self.c.borrow()).moves });
102+
return (({ (*c.borrow()).copies } * 10) + { (*c.borrow()).moves });
103103
}
104104
)));
105105
assert!((({ (*f.borrow()).call() }) == 10));
@@ -116,7 +116,7 @@ fn main_0() -> i32 {
116116
Rc::new(RefCell::new(Counted::copy_from({ c.as_pointer() })));
117117
},
118118
|| -> Counted {
119-
return Counted::copy_from({ self.c.as_pointer() });
119+
return Counted::copy_from({ c.as_pointer() });
120120
}
121121
)
122122
.call()
@@ -136,8 +136,8 @@ fn main_0() -> i32 {
136136
)));
137137
},
138138
|| -> i32 {
139-
return ({ (*self.arr.borrow())[(0) as usize].copies } + {
140-
(*self.arr.borrow())[(1) as usize].copies
139+
return ({ (*arr.borrow())[(0) as usize].copies } + {
140+
(*arr.borrow())[(1) as usize].copies
141141
});
142142
}
143143
)));

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ fn main_0() -> i32 {
2222
},
2323
|x: i32| -> i32 {
2424
let x: Value<i32> = Rc::new(RefCell::new(x));
25-
return ((((*self.a.borrow()) + (*self.b.borrow())) + (*self.c.borrow()))
26-
+ (*x.borrow()));
25+
return ((((*a.borrow()) + (*b.borrow())) + (*c.borrow())) + (*x.borrow()));
2726
}
2827
)));
2928
assert!((({ (*by_value.borrow()).call(10,) }) == 16));
@@ -37,7 +36,7 @@ fn main_0() -> i32 {
3736
},
3837
|x: i32| -> i32 {
3938
let x: Value<i32> = Rc::new(RefCell::new(x));
40-
return ((((self.a.read()) + (self.b.read())) + (self.c.read())) + (*x.borrow()));
39+
return ((((a.read()) + (b.read())) + (c.read())) + (*x.borrow()));
4140
}
4241
)));
4342
assert!((({ (*by_ref.borrow()).call(10,) }) == 115));
@@ -52,10 +51,10 @@ fn main_0() -> i32 {
5251
|x: i32| -> i32 {
5352
let x: Value<i32> = Rc::new(RefCell::new(x));
5453
{
55-
let _ptr = self.c.clone();
54+
let _ptr = c.clone();
5655
_ptr.write(_ptr.read() + (*x.borrow()))
5756
};
58-
return (((*self.a.borrow()) + (*self.b.borrow())) + (self.c.read()));
57+
return (((*a.borrow()) + (*b.borrow())) + (c.read()));
5958
}
6059
)));
6160
assert!((({ (*mixed.borrow()).call(1,) }) == ((100 + 200) + 4)));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ impl SImpl for Ptr<S> {
4343
},
4444
|| -> i32 {
4545
{
46-
let _ptr = field!(self.this_.as_pointer(), n);
46+
let _ptr = field!(this_.as_pointer(), n);
4747
_ptr.write(_ptr.read() + 10)
4848
};
49-
return self.this_.as_pointer().with(|__s| __s.n);
49+
return this_.as_pointer().with(|__s| __s.n);
5050
}
5151
)));
5252
let r: Value<i32> = Rc::new(RefCell::new(({ (*f.borrow()).call() }).clone()));
@@ -58,7 +58,7 @@ impl SImpl for Ptr<S> {
5858
let this_: Value<S> = Rc::new(RefCell::new((*(*self).upgrade().deref()).clone()));
5959
},
6060
|| -> i32 {
61-
return ({ SImpl::twice(&self.this_.as_pointer()) });
61+
return ({ SImpl::twice(&this_.as_pointer()) });
6262
}
6363
)));
6464
field!((*self), n).write(99);
@@ -72,7 +72,7 @@ impl SImpl for Ptr<S> {
7272
let k: Value<i32> = Rc::new(RefCell::new((*k.borrow())));
7373
},
7474
|| -> i32 {
75-
return (self.this_.as_pointer().with(|__s| __s.n) + (*self.k.borrow()));
75+
return (this_.as_pointer().with(|__s| __s.n) + (*k.borrow()));
7676
}
7777
)));
7878
field!((*self), n).write(0);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl SImpl for Ptr<S> {
5454
|k: i32| {
5555
let k: Value<i32> = Rc::new(RefCell::new(k));
5656
{
57-
let _ptr = field!((*self.this_.borrow()).clone(), n);
57+
let _ptr = field!((*this_.borrow()).clone(), n);
5858
_ptr.write(_ptr.read() + (*k.borrow()))
5959
};
6060
}
@@ -70,7 +70,7 @@ impl SImpl for Ptr<S> {
7070
},
7171
|k: i32| {
7272
let k: Value<i32> = Rc::new(RefCell::new(k));
73-
({ SImpl::add(&(*self.this_.borrow()).clone(), (*k.borrow())) });
73+
({ SImpl::add(&(*this_.borrow()).clone(), (*k.borrow())) });
7474
}
7575
)));
7676
({ (*inc.borrow()).call((*by.borrow())) });
@@ -81,7 +81,7 @@ impl SImpl for Ptr<S> {
8181
let this_: Value<Ptr<S>> = Rc::new(RefCell::new((*self).clone()));
8282
},
8383
|| -> i32 {
84-
return ({ SImpl::scaled(&(*self.this_.borrow()).clone()) });
84+
return ({ SImpl::scaled(&(*this_.borrow()).clone()) });
8585
}
8686
)));
8787
return ({ (*get.borrow()).call() }).clone();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main_0() -> i32 {
2626
},
2727
|x: i32| -> i32 {
2828
let x: Value<i32> = Rc::new(RefCell::new(x));
29-
return ((*x.borrow()) * (*self.factor.borrow()));
29+
return ((*x.borrow()) * (*factor.borrow()));
3030
}
3131
)));
3232
assert!((({ (*scale.borrow()).call(4,) }) == 12));
@@ -39,7 +39,7 @@ fn main_0() -> i32 {
3939
let p: Value<Ptr<i32>> = Rc::new(RefCell::new((*p.borrow()).clone()));
4040
},
4141
|| -> i32 {
42-
return ((*self.p.borrow()).read());
42+
return ((*p.borrow()).read());
4343
}
4444
)));
4545
(*slot.borrow_mut()) = 8;
@@ -50,7 +50,7 @@ fn main_0() -> i32 {
5050
let s: Value<S> = Rc::new(RefCell::new((*s.borrow()).clone()));
5151
},
5252
|| -> i32 {
53-
return ({ (*self.s.borrow()).x } + { (*self.s.borrow()).y });
53+
return ({ (*s.borrow()).x } + { (*s.borrow()).y });
5454
}
5555
)));
5656
(*s.borrow_mut()).x = 50;
@@ -62,7 +62,7 @@ fn main_0() -> i32 {
6262
},
6363
|x: i32| -> i32 {
6464
let x: Value<i32> = Rc::new(RefCell::new(x));
65-
return ((*x.borrow()) + (*self.y.borrow()));
65+
return ((*x.borrow()) + (*y.borrow()));
6666
}
6767
)));
6868
assert!((({ (*shifted.borrow()).call(5,) }) == 16));

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn main_0() -> i32 {
4343
let h: Value<Owner> = Rc::new(RefCell::new(Owner::move_from({ o.as_pointer() })));
4444
},
4545
|| -> i32 {
46-
return ({ (*self.h.borrow()).p.clone() }.read());
46+
return ({ (*h.borrow()).p.clone() }.read());
4747
}
4848
)));
4949
assert!(({ (*o.borrow()).p.clone() }).is_null());
@@ -58,10 +58,10 @@ fn main_0() -> i32 {
5858
},
5959
|| {
6060
{
61-
let _ptr = self.total.clone();
62-
_ptr.write(_ptr.read() + { ({ (*self.h.borrow()).p.clone() }.read()) })
61+
let _ptr = total.clone();
62+
_ptr.write(_ptr.read() + { ({ (*h.borrow()).p.clone() }.read()) })
6363
};
64-
{ (*self.h.borrow()).p.clone() }.write(0);
64+
{ (*h.borrow()).p.clone() }.write(0);
6565
}
6666
)));
6767
({ (*consume.borrow()).call() });
@@ -90,7 +90,7 @@ impl OwnerImpl for Ptr<Owner> {
9090
Rc::new(RefCell::new(Owner::move_from({ (*self).clone() })));
9191
},
9292
|| -> i32 {
93-
return ({ (*self.self_.borrow()).p.clone() }.read());
93+
return ({ (*self_.borrow()).p.clone() }.read());
9494
}
9595
);
9696
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main_0() -> i32 {
1717
let start: Value<i32> = Rc::new(RefCell::new((*start.borrow())));
1818
},
1919
|| -> i32 {
20-
return (*self.start.borrow_mut()).postfix_inc();
20+
return (*start.borrow_mut()).postfix_inc();
2121
}
2222
)));
2323
assert!((({ (*next.borrow()).call() }) == 5));
@@ -31,8 +31,8 @@ fn main_0() -> i32 {
3131
},
3232
|x: i32| -> i32 {
3333
let x: Value<i32> = Rc::new(RefCell::new(x));
34-
(*self.total.borrow_mut()) += (*x.borrow());
35-
return (*self.total.borrow());
34+
(*total.borrow_mut()) += (*x.borrow());
35+
return (*total.borrow());
3636
}
3737
)));
3838
assert!((({ (*accumulate.borrow()).call(1,) }) == 1));

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ fn main_0() -> i32 {
2626
let y: Value<i32> = Rc::new(RefCell::new(y));
2727
let inner: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(lambda!(
2828
{
29-
let x: Ptr<i32> = (self.x).clone();
29+
let x: Ptr<i32> = (x).clone();
3030
let y: Value<i32> = Rc::new(RefCell::new((*y.borrow())));
3131
},
3232
|z: i32| -> i32 {
3333
let z: Value<i32> = Rc::new(RefCell::new(z));
34-
return (((self.x.read()) + (*self.y.borrow())) + (*z.borrow()));
34+
return (((x.read()) + (*y.borrow())) + (*z.borrow()));
3535
}
3636
)));
3737
return ({ (*inner.borrow()).call(1) });
@@ -57,14 +57,12 @@ impl SImpl for Ptr<S> {
5757
let y: Value<i32> = Rc::new(RefCell::new(y));
5858
let inner: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(lambda!(
5959
{
60-
let this_: Value<Ptr<S>> =
61-
Rc::new(RefCell::new((*self.this_.borrow()).clone()));
60+
let this_: Value<Ptr<S>> = Rc::new(RefCell::new((*this_.borrow()).clone()));
6261
let y: Value<i32> = Rc::new(RefCell::new((*y.borrow())));
6362
},
6463
|z: i32| -> i32 {
6564
let z: Value<i32> = Rc::new(RefCell::new(z));
66-
return (((*self.this_.borrow()).clone().with(|__s| __s.v)
67-
+ (*self.y.borrow()))
65+
return (((*this_.borrow()).clone().with(|__s| __s.v) + (*y.borrow()))
6866
+ (*z.borrow()));
6967
}
7068
)));

0 commit comments

Comments
 (0)