Skip to content

Commit 4edadd8

Browse files
committed
Update tests
1 parent d2881b5 commit 4edadd8

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

‎tests/unit/concepts.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ADDITIONAL_COMPILE_FLAGS: -std=c++20
2+
#include <cassert>
3+
#include <concepts>
4+
5+
template <typename T>
6+
concept Small = sizeof(T) <= 4;
7+
8+
static_assert(Small<int>);
9+
10+
template <typename T> bool is_small() { return Small<T>; }
11+
12+
template <typename T> int pick(T x) {
13+
if (std::integral<T> && Small<T>) {
14+
return 1;
15+
}
16+
return 2;
17+
}
18+
19+
int main() {
20+
static_assert(!Small<long>);
21+
assert(is_small<char>());
22+
assert(!is_small<double>());
23+
assert(pick(1) == 1);
24+
assert(pick(1L) == 2);
25+
assert(pick(1.0f) == 2);
26+
return 0;
27+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
pub fn is_small_0() -> bool {
10+
return true;
11+
}
12+
pub fn is_small_1() -> bool {
13+
return false;
14+
}
15+
pub fn pick_2(x: i32) -> i32 {
16+
let x: Value<i32> = Rc::new(RefCell::new(x));
17+
if (true) && (true) {
18+
return 1;
19+
}
20+
return 2;
21+
}
22+
pub fn pick_3(x: i64) -> i32 {
23+
let x: Value<i64> = Rc::new(RefCell::new(x));
24+
if (true) && (false) {
25+
return 1;
26+
}
27+
return 2;
28+
}
29+
pub fn pick_4(x: f32) -> i32 {
30+
let x: Value<f32> = Rc::new(RefCell::new(x));
31+
if (false) && (true) {
32+
return 1;
33+
}
34+
return 2;
35+
}
36+
pub fn main() {
37+
std::process::exit(main_0());
38+
}
39+
fn main_0() -> i32 {
40+
assert!(({ is_small_0() }));
41+
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));
45+
return 0;
46+
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
pub unsafe fn is_small_0() -> bool {
10+
return true;
11+
}
12+
pub unsafe fn is_small_1() -> bool {
13+
return false;
14+
}
15+
pub unsafe fn pick_2(mut x: i32) -> i32 {
16+
if (true) && (true) {
17+
return 1;
18+
}
19+
return 2;
20+
}
21+
pub unsafe fn pick_3(mut x: i64) -> i32 {
22+
if (true) && (false) {
23+
return 1;
24+
}
25+
return 2;
26+
}
27+
pub unsafe fn pick_4(mut x: f32) -> i32 {
28+
if (false) && (true) {
29+
return 1;
30+
}
31+
return 2;
32+
}
33+
pub fn main() {
34+
unsafe {
35+
std::process::exit(main_0() as i32);
36+
}
37+
}
38+
unsafe fn main_0() -> i32 {
39+
assert!((unsafe { is_small_0() }));
40+
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)));
44+
return 0;
45+
}

0 commit comments

Comments
 (0)