Skip to content

Commit d56970d

Browse files
committed
Add expr_as_bool C and C++ tests
1 parent d9ff51f commit d56970d

8 files changed

Lines changed: 316 additions & 0 deletions

File tree

tests/unit/expr_as_bool_c.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
4+
int main() {
5+
int a = 0;
6+
int b;
7+
8+
if (b = a) {
9+
}
10+
while ((b = a) != 0) {
11+
}
12+
if (a) {
13+
}
14+
if (a == b) {
15+
}
16+
if (a < b) {
17+
}
18+
19+
assert(a == b);
20+
assert(!(a = b));
21+
22+
bool c;
23+
c = a = b;
24+
c = (b = a) != 0;
25+
c = a;
26+
c = a == b;
27+
c = a < b;
28+
return 0;
29+
}

tests/unit/expr_as_bool_cpp.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
4+
int main() {
5+
int a = 0;
6+
int b;
7+
8+
if (b = a) {
9+
}
10+
while ((b = a) != 0) {
11+
}
12+
if (a) {
13+
}
14+
if (a == b) {
15+
}
16+
if (a < b) {
17+
}
18+
19+
assert(a == b);
20+
assert(!(a = b));
21+
22+
bool c;
23+
c = a = b;
24+
c = (b = a) != 0;
25+
c = a;
26+
c = a == b;
27+
c = a < b;
28+
return 0;
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn main() {
11+
std::process::exit(main_0());
12+
}
13+
fn main_0() -> i32 {
14+
let a: Value<i32> = Rc::new(RefCell::new(0));
15+
let b: Value<i32> = <Value<i32>>::default();
16+
if ({
17+
(*b.borrow_mut()) = (*a.borrow());
18+
(*b.borrow())
19+
} != 0)
20+
{}
21+
return 0;
22+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn main() {
11+
std::process::exit(main_0());
12+
}
13+
fn main_0() -> i32 {
14+
let a: Value<i32> = Rc::new(RefCell::new(0));
15+
let b: Value<i32> = <Value<i32>>::default();
16+
if ({
17+
(*b.borrow_mut()) = (*a.borrow());
18+
(*b.borrow())
19+
} != 0)
20+
{}
21+
'loop_: while ((({
22+
(*b.borrow_mut()) = (*a.borrow());
23+
(*b.borrow())
24+
}) as i32)
25+
!= 0)
26+
{}
27+
if ((*a.borrow()) != 0) {}
28+
if ((*a.borrow()) == (*b.borrow())) {}
29+
if ((*a.borrow()) < (*b.borrow())) {}
30+
assert!(((*a.borrow()) == (*b.borrow())));
31+
assert!(
32+
(!(({
33+
(*a.borrow_mut()) = (*b.borrow());
34+
(*a.borrow())
35+
}) as i32)
36+
!= 0)
37+
);
38+
let c: Value<bool> = <Value<bool>>::default();
39+
(*c.borrow_mut()) = ({
40+
(*a.borrow_mut()) = (*b.borrow());
41+
(*a.borrow())
42+
} != 0);
43+
(*c.borrow_mut()) = ((({
44+
(*b.borrow_mut()) = (*a.borrow());
45+
(*b.borrow())
46+
}) as i32)
47+
!= 0);
48+
(*c.borrow_mut()) = ((*a.borrow()) != 0);
49+
(*c.borrow_mut()) = ((*a.borrow()) == (*b.borrow()));
50+
(*c.borrow_mut()) = ((*a.borrow()) < (*b.borrow()));
51+
return 0;
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::AsFd;
9+
use std::rc::{Rc, Weak};
10+
pub fn main() {
11+
std::process::exit(main_0());
12+
}
13+
fn main_0() -> i32 {
14+
let a: Value<i32> = Rc::new(RefCell::new(0));
15+
let b: Value<i32> = <Value<i32>>::default();
16+
if ({
17+
(*b.borrow_mut()) = (*a.borrow());
18+
(*b.borrow())
19+
} != 0)
20+
{}
21+
'loop_: while ((({
22+
(*b.borrow_mut()) = (*a.borrow());
23+
(*b.borrow())
24+
}) as i32)
25+
!= 0)
26+
{}
27+
if ((*a.borrow()) != 0) {}
28+
if ((*a.borrow()) == (*b.borrow())) {}
29+
if ((*a.borrow()) < (*b.borrow())) {}
30+
assert!(((*a.borrow()) == (*b.borrow())));
31+
assert!(
32+
!((({
33+
(*a.borrow_mut()) = (*b.borrow());
34+
(*a.borrow())
35+
}) as i32)
36+
!= 0)
37+
);
38+
let c: Value<bool> = <Value<bool>>::default();
39+
(*c.borrow_mut()) = ({
40+
(*a.borrow_mut()) = (*b.borrow());
41+
(*a.borrow())
42+
} != 0);
43+
(*c.borrow_mut()) = ((({
44+
(*b.borrow_mut()) = (*a.borrow());
45+
(*b.borrow())
46+
}) as i32)
47+
!= 0);
48+
(*c.borrow_mut()) = ((*a.borrow()) != 0);
49+
(*c.borrow_mut()) = ((*a.borrow()) == (*b.borrow()));
50+
(*c.borrow_mut()) = ((*a.borrow()) < (*b.borrow()));
51+
return 0;
52+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
9+
use std::rc::Rc;
10+
pub fn main() {
11+
unsafe {
12+
std::process::exit(main_0() as i32);
13+
}
14+
}
15+
unsafe fn main_0() -> i32 {
16+
let mut a: i32 = 0;
17+
let mut b: i32 = 0_i32;
18+
if ({
19+
b = a;
20+
b
21+
} != 0)
22+
{}
23+
return 0;
24+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
9+
use std::rc::Rc;
10+
pub fn main() {
11+
unsafe {
12+
std::process::exit(main_0() as i32);
13+
}
14+
}
15+
unsafe fn main_0() -> i32 {
16+
let mut a: i32 = 0;
17+
let mut b: i32 = 0_i32;
18+
if ({
19+
b = a;
20+
b
21+
} != 0)
22+
{}
23+
'loop_: while ((({
24+
b = a;
25+
b
26+
}) as i32)
27+
!= (0))
28+
{}
29+
if (a != 0) {}
30+
if ((a) == (b)) {}
31+
if ((a) < (b)) {}
32+
assert!(((a) == (b)));
33+
assert!(
34+
(!(({
35+
a = b;
36+
a
37+
}) as i32)
38+
!= 0)
39+
);
40+
let mut c: bool = false;
41+
c = ({
42+
a = b;
43+
a
44+
} != 0);
45+
c = ((({
46+
b = a;
47+
b
48+
}) as i32)
49+
!= (0));
50+
c = (a != 0);
51+
c = ((a) == (b));
52+
c = ((a) < (b));
53+
return 0;
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::Seek;
7+
use std::io::{Read, Write};
8+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
9+
use std::rc::Rc;
10+
pub fn main() {
11+
unsafe {
12+
std::process::exit(main_0() as i32);
13+
}
14+
}
15+
unsafe fn main_0() -> i32 {
16+
let mut a: i32 = 0;
17+
let mut b: i32 = 0_i32;
18+
if ({
19+
b = a;
20+
b
21+
} != 0)
22+
{}
23+
'loop_: while ((({
24+
b = a;
25+
b
26+
}) as i32)
27+
!= (0))
28+
{}
29+
if (a != 0) {}
30+
if ((a) == (b)) {}
31+
if ((a) < (b)) {}
32+
assert!(((a) == (b)));
33+
assert!(
34+
!((({
35+
a = b;
36+
a
37+
}) as i32)
38+
!= 0)
39+
);
40+
let mut c: bool = false;
41+
c = ({
42+
a = b;
43+
a
44+
} != 0);
45+
c = ((({
46+
b = a;
47+
b
48+
}) as i32)
49+
!= (0));
50+
c = (a != 0);
51+
c = ((a) == (b));
52+
c = ((a) < (b));
53+
return 0;
54+
}

0 commit comments

Comments
 (0)