Skip to content

Commit 6db51e3

Browse files
committed
subs_repetition: Add simple test cases
1 parent ded1aca commit 6db51e3

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// { dg-output "18\n" }
2+
extern "C" {
3+
fn printf(s: *const i8, ...);
4+
}
5+
6+
fn print_int(value: i32) {
7+
let s = "%d\n\0" as *const str as *const i8;
8+
printf(s, value);
9+
}
10+
11+
macro_rules! add_exprs {
12+
($($e:expr)*) => (0 $(+ $e)*)
13+
}
14+
15+
fn main() -> i32 {
16+
// 1 + 2 + 15 => 18
17+
print_int(add_exprs!(1 2 15));
18+
19+
0
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// { dg-output "2" }
2+
extern "C" {
3+
fn printf(s: *const i8, ...);
4+
}
5+
6+
fn print_int(value: i32) {
7+
let s = "%d\n\0";
8+
let s_p = s as *const str;
9+
let c_p = s_p as *const i8;
10+
unsafe { printf(c_p, value); }
11+
}
12+
13+
macro_rules! add_exprs {
14+
($($e:expr)?) => (0 $(+ $e)?)
15+
}
16+
17+
fn main() -> i32 {
18+
// 2
19+
print_int(add_exprs!(2));
20+
21+
0
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// { dg-output "0\n" }
2+
extern "C" {
3+
fn printf(s: *const i8, ...);
4+
}
5+
6+
fn print_int(value: i32) {
7+
let s = "%d\n\0" as *const str as *const i8;
8+
printf(s, value);
9+
}
10+
11+
macro_rules! add_exprs {
12+
($($e:expr)?) => (0 $(+ $e)?)
13+
}
14+
15+
fn main() -> i32 {
16+
// 0
17+
print_int(add_exprs!());
18+
19+
0
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// { dg-output "18\n" }
2+
extern "C" {
3+
fn printf(s: *const i8, ...);
4+
}
5+
6+
fn print_int(value: i32) {
7+
let s = "%d\n\0" as *const str as *const i8;
8+
printf(s, value);
9+
}
10+
11+
macro_rules! add_exprs {
12+
($($e:expr)+) => (0 $(+ $e)+)
13+
}
14+
15+
fn main() -> i32 {
16+
// 1 + 2 + 15 => 18
17+
print_int(add_exprs!(1 2 15));
18+
19+
0
20+
}

0 commit comments

Comments
 (0)