Skip to content

Commit cae6949

Browse files
committed
Update tests
1 parent a863d43 commit cae6949

6 files changed

Lines changed: 122 additions & 0 deletions

File tree

‎tests/unit/constexpr_function.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ constexpr int scaled(int x) {
1313

1414
constexpr double half(double x) { return x / 2.0; }
1515

16+
struct Flag {
17+
int v;
18+
constexpr explicit operator bool() const { return v != 0; }
19+
};
20+
21+
constexpr int use(Flag f) {
22+
assert(f);
23+
return f.v;
24+
}
25+
26+
constexpr int checked(int x) {
27+
assert(x > 0);
28+
return x + 1;
29+
}
30+
1631
struct P {
1732
int v;
1833
constexpr int get() const { return v; }
@@ -25,6 +40,14 @@ int main() {
2540
assert(scaled(3) == 3);
2641
assert(scaled(-3) == 6);
2742
assert(half(5.0) == 2.5);
43+
assert(checked(1) == 2);
44+
constexpr int c = checked(4);
45+
assert(c == 5);
46+
assert(use(Flag{2}) == 2);
47+
constexpr int u = use(Flag{3});
48+
assert(u == 3);
49+
int *ptr = arr;
50+
assert(ptr);
2851
P p{9};
2952
assert(p.get() == 9);
3053
constexpr int k = scaled(4);

‎tests/unit/operator_other_member.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ int main() {
3030
assert(false);
3131
}
3232
S z{0};
33+
assert(s);
3334
assert(!z);
35+
assert(s && !z);
3436
Static st;
3537
assert(st(6, 7) == 42);
3638
return 0;

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,42 @@ pub fn half_3(x: f64) -> f64 {
2626
return ((*x.borrow()) / 2.0E+0);
2727
}
2828
#[derive(Default)]
29+
pub struct Flag {
30+
pub v: Value<i32>,
31+
}
32+
impl Clone for Flag {
33+
fn clone(&self) -> Self {
34+
let __this: Value<Flag> = Rc::new(RefCell::new(Self {
35+
v: Rc::new(RefCell::new((*self.v.borrow()))),
36+
}));
37+
let this: Ptr<Flag> = __this.as_pointer();
38+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
39+
}
40+
}
41+
impl ByteRepr for Flag {
42+
fn byte_size() -> usize {
43+
4
44+
}
45+
fn to_bytes(&self, buf: &mut [u8]) {
46+
(*self.v.borrow()).to_bytes(&mut buf[0..4]);
47+
}
48+
fn from_bytes(buf: &[u8]) -> Self {
49+
Self {
50+
v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
51+
}
52+
}
53+
}
54+
pub fn use_4(f: Flag) -> i32 {
55+
let f: Value<Flag> = Rc::new(RefCell::new(f));
56+
assert!(({ FlagImpl::operator__Bool(&f.as_pointer(),) }));
57+
return (*(*f.borrow()).v.borrow());
58+
}
59+
pub fn checked_5(x: i32) -> i32 {
60+
let x: Value<i32> = Rc::new(RefCell::new(x));
61+
assert!(((*x.borrow()) > 0));
62+
return ((*x.borrow()) + 1);
63+
}
64+
#[derive(Default)]
2965
pub struct P {
3066
pub v: Value<i32>,
3167
}
@@ -62,6 +98,26 @@ fn main_0() -> i32 {
6298
assert!((({ scaled_2(3,) }) == 3));
6399
assert!((({ scaled_2(-3_i32,) }) == 6));
64100
assert!((({ half_3(5.0E+0,) }) == 2.5E+0));
101+
assert!((({ checked_5(1,) }) == 2));
102+
let c: Value<i32> = Rc::new(RefCell::new(({ checked_5(4) })));
103+
assert!(((*c.borrow()) == 5));
104+
assert!(
105+
(({
106+
use_4(Flag {
107+
v: Rc::new(RefCell::new(2)),
108+
})
109+
}) == 2)
110+
);
111+
let u: Value<i32> = Rc::new(RefCell::new(
112+
({
113+
use_4(Flag {
114+
v: Rc::new(RefCell::new(3)),
115+
})
116+
}),
117+
));
118+
assert!(((*u.borrow()) == 3));
119+
let ptr: Value<Ptr<i32>> = Rc::new(RefCell::new((arr.as_pointer() as Ptr<i32>)));
120+
assert!(!(*ptr.borrow()).is_null());
65121
let p: Value<P> = Rc::new(RefCell::new(P {
66122
v: Rc::new(RefCell::new(9)),
67123
}));
@@ -70,6 +126,14 @@ fn main_0() -> i32 {
70126
assert!(((*k.borrow()) == 4));
71127
return 0;
72128
}
129+
pub trait FlagImpl {
130+
fn operator__Bool(&self) -> bool;
131+
}
132+
impl FlagImpl for Ptr<Flag> {
133+
fn operator__Bool(&self) -> bool {
134+
return ((*(*(*self).upgrade().deref()).v.borrow()) != 0);
135+
}
136+
}
73137
pub trait PImpl {
74138
fn get(&self) -> i32;
75139
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ fn main_0() -> i32 {
7272
let z: Value<S> = Rc::new(RefCell::new(S {
7373
v: Rc::new(RefCell::new(0)),
7474
}));
75+
assert!(({ SImpl::operator__Bool(&s.as_pointer(),) }));
7576
assert!(!({ SImpl::operator__Bool(&z.as_pointer(),) }));
77+
assert!(
78+
({ SImpl::operator__Bool(&s.as_pointer(),) })
79+
&& (!({ SImpl::operator__Bool(&z.as_pointer(),) }))
80+
);
7681
let st: Value<Static> = Rc::new(RefCell::new(<Static>::default()));
7782
assert!((({ Static::operator_call(6, 7,) }) == 42));
7883
return 0;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ pub unsafe fn half_3(mut x: f64) -> f64 {
2323
}
2424
#[repr(C)]
2525
#[derive(Copy, Clone, Default)]
26+
pub struct Flag {
27+
pub v: i32,
28+
}
29+
impl Flag {
30+
pub unsafe fn operator__Bool(&self) -> bool {
31+
return ((self.v) != (0));
32+
}
33+
}
34+
pub unsafe fn use_4(mut f: Flag) -> i32 {
35+
assert!((unsafe { Flag::operator__Bool(&f,) }));
36+
return f.v;
37+
}
38+
pub unsafe fn checked_5(mut x: i32) -> i32 {
39+
assert!(((x) > (0)));
40+
return ((x) + (1));
41+
}
42+
#[repr(C)]
43+
#[derive(Copy, Clone, Default)]
2644
pub struct P {
2745
pub v: i32,
2846
}
@@ -44,6 +62,14 @@ unsafe fn main_0() -> i32 {
4462
assert!(((unsafe { scaled_2(3,) }) == (3)));
4563
assert!(((unsafe { scaled_2(-3_i32,) }) == (6)));
4664
assert!(((unsafe { half_3(5.0E+0,) }) == (2.5E+0)));
65+
assert!(((unsafe { checked_5(1,) }) == (2)));
66+
let c: i32 = (unsafe { checked_5(4) });
67+
assert!(((c) == (5)));
68+
assert!(((unsafe { use_4(Flag { v: 2 },) }) == (2)));
69+
let u: i32 = (unsafe { use_4(Flag { v: 3 }) });
70+
assert!(((u) == (3)));
71+
let mut ptr: *mut i32 = arr.as_mut_ptr();
72+
assert!(!(ptr).is_null());
4773
let mut p: P = P { v: 9 };
4874
assert!(((unsafe { P::get(&p,) }) == (9)));
4975
let k: i32 = (unsafe { scaled_2(4) });

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ unsafe fn main_0() -> i32 {
6363
assert!(false);
6464
}
6565
let mut z: S = S { v: 0 };
66+
assert!((unsafe { S::operator__Bool(&s,) }));
6667
assert!(!(unsafe { S::operator__Bool(&z,) }));
68+
assert!((unsafe { S::operator__Bool(&s,) }) && (!(unsafe { S::operator__Bool(&z,) })));
6769
let mut st: Static = <Static>::default();
6870
assert!(((unsafe { Static::operator_call(6, 7,) }) == (42)));
6971
return 0;

0 commit comments

Comments
 (0)