Skip to content

Commit fe29404

Browse files
committed
Update tests
1 parent 82ea91e commit fe29404

3 files changed

Lines changed: 81 additions & 12 deletions

File tree

‎tests/unit/concepts.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@ concept Small = sizeof(T) <= 4;
77

88
static_assert(Small<int>);
99

10+
template <typename T>
11+
concept HasSize = requires(T t) {
12+
{ t.size() } -> std::same_as<int>;
13+
};
14+
15+
struct Sized {
16+
int size() { return 4; }
17+
};
18+
1019
template <typename T> bool is_small() { return Small<T>; }
1120

21+
template <typename T> bool has_size() { return requires(T t) { t.size(); }; }
22+
1223
template <typename T> int pick(T x) {
1324
if (std::integral<T> && Small<T>) {
1425
return 1;
@@ -20,6 +31,10 @@ int main() {
2031
static_assert(!Small<long>);
2132
assert(is_small<char>());
2233
assert(!is_small<double>());
34+
assert(HasSize<Sized>);
35+
assert(!HasSize<int>);
36+
assert(has_size<Sized>());
37+
assert(!has_size<int>());
2338
assert(pick(1) == 1);
2439
assert(pick(1L) == 2);
2540
assert(pick(1.0f) == 2);

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,51 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9+
#[derive(Default)]
10+
pub struct Sized {}
11+
impl Clone for Sized {
12+
fn clone(&self) -> Self {
13+
let __this: Value<Sized> = Rc::new(RefCell::new(Self {}));
14+
let this: Ptr<Sized> = __this.as_pointer();
15+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
16+
}
17+
}
18+
impl ByteRepr for Sized {
19+
fn byte_size() -> usize {
20+
1
21+
}
22+
fn to_bytes(&self, buf: &mut [u8]) {}
23+
fn from_bytes(buf: &[u8]) -> Self {
24+
Self {}
25+
}
26+
}
927
pub fn is_small_0() -> bool {
1028
return true;
1129
}
1230
pub fn is_small_1() -> bool {
1331
return false;
1432
}
15-
pub fn pick_2(x: i32) -> i32 {
33+
pub fn has_size_2() -> bool {
34+
return true;
35+
}
36+
pub fn has_size_3() -> bool {
37+
return false;
38+
}
39+
pub fn pick_4(x: i32) -> i32 {
1640
let x: Value<i32> = Rc::new(RefCell::new(x));
1741
if (true) && (true) {
1842
return 1;
1943
}
2044
return 2;
2145
}
22-
pub fn pick_3(x: i64) -> i32 {
46+
pub fn pick_5(x: i64) -> i32 {
2347
let x: Value<i64> = Rc::new(RefCell::new(x));
2448
if (true) && (false) {
2549
return 1;
2650
}
2751
return 2;
2852
}
29-
pub fn pick_4(x: f32) -> i32 {
53+
pub fn pick_6(x: f32) -> i32 {
3054
let x: Value<f32> = Rc::new(RefCell::new(x));
3155
if (false) && (true) {
3256
return 1;
@@ -39,8 +63,20 @@ pub fn main() {
3963
fn main_0() -> i32 {
4064
assert!(({ is_small_0() }));
4165
assert!(!({ is_small_1() }));
42-
assert!((({ pick_2(1,) }) == 1));
43-
assert!((({ pick_3(1_i64,) }) == 2));
44-
assert!((({ pick_4(1.0E+0,) }) == 2));
66+
assert!(true);
67+
assert!(!false);
68+
assert!(({ has_size_2() }));
69+
assert!(!({ has_size_3() }));
70+
assert!((({ pick_4(1,) }) == 1));
71+
assert!((({ pick_5(1_i64,) }) == 2));
72+
assert!((({ pick_6(1.0E+0,) }) == 2));
4573
return 0;
4674
}
75+
pub trait SizedImpl {
76+
fn size(&self) -> i32;
77+
}
78+
impl SizedImpl for Ptr<Sized> {
79+
fn size(&self) -> i32 {
80+
return 4;
81+
}
82+
}

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,39 @@ use std::collections::BTreeMap;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
9+
#[repr(C)]
10+
#[derive(Copy, Clone, Default)]
11+
pub struct Sized {}
12+
impl Sized {
13+
pub unsafe fn size(&mut self) -> i32 {
14+
return 4;
15+
}
16+
}
917
pub unsafe fn is_small_0() -> bool {
1018
return true;
1119
}
1220
pub unsafe fn is_small_1() -> bool {
1321
return false;
1422
}
15-
pub unsafe fn pick_2(mut x: i32) -> i32 {
23+
pub unsafe fn has_size_2() -> bool {
24+
return true;
25+
}
26+
pub unsafe fn has_size_3() -> bool {
27+
return false;
28+
}
29+
pub unsafe fn pick_4(mut x: i32) -> i32 {
1630
if (true) && (true) {
1731
return 1;
1832
}
1933
return 2;
2034
}
21-
pub unsafe fn pick_3(mut x: i64) -> i32 {
35+
pub unsafe fn pick_5(mut x: i64) -> i32 {
2236
if (true) && (false) {
2337
return 1;
2438
}
2539
return 2;
2640
}
27-
pub unsafe fn pick_4(mut x: f32) -> i32 {
41+
pub unsafe fn pick_6(mut x: f32) -> i32 {
2842
if (false) && (true) {
2943
return 1;
3044
}
@@ -38,8 +52,12 @@ pub fn main() {
3852
unsafe fn main_0() -> i32 {
3953
assert!((unsafe { is_small_0() }));
4054
assert!(!(unsafe { is_small_1() }));
41-
assert!(((unsafe { pick_2(1,) }) == (1)));
42-
assert!(((unsafe { pick_3(1_i64,) }) == (2)));
43-
assert!(((unsafe { pick_4(1.0E+0,) }) == (2)));
55+
assert!(true);
56+
assert!(!false);
57+
assert!((unsafe { has_size_2() }));
58+
assert!(!(unsafe { has_size_3() }));
59+
assert!(((unsafe { pick_4(1,) }) == (1)));
60+
assert!(((unsafe { pick_5(1_i64,) }) == (2)));
61+
assert!(((unsafe { pick_6(1.0E+0,) }) == (2)));
4462
return 0;
4563
}

0 commit comments

Comments
 (0)