Skip to content

Commit 3d488f8

Browse files
committed
Add pretty printing tests for if/else.
The AST pretty printing is a bit wonky. The HIR pretty printing is extremely wonky.
1 parent dc8fe1f commit 3d488f8

File tree

4 files changed

+224
-0
lines changed

4 files changed

+224
-0
lines changed

tests/pretty/hir-if-else.pp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#[prelude_import]
2+
use ::std::prelude::rust_2015::*;
3+
#[macro_use]
4+
extern crate std;
5+
//@ pretty-compare-only
6+
//@ pretty-mode:hir
7+
//@ pp-exact:hir-if-else.pp
8+
9+
fn f(x: u32,
10+
y:
11+
u32) {
12+
let mut a = 0;
13+
if x > y { a = 1; } else { a = 2; }
14+
15+
if x < 1
16+
{
17+
a = 1;
18+
} else if x < 2
19+
{
20+
a = 2;
21+
} else if x < 3
22+
{
23+
a = 3;
24+
} else if x < 4 { a = 4; } else { a = 5; }
25+
26+
if x < y
27+
{
28+
a += 1;
29+
a += 1;
30+
a += 1;
31+
a += 1;
32+
a += 1;
33+
a += 1;
34+
} else { a += 1; a += 1; a += 1; a += 1; a += 1; a += 1; }
35+
36+
if x < 1
37+
{
38+
if x < 2
39+
{
40+
if x < 3
41+
{
42+
a += 1;
43+
} else if x < 4
44+
{ a += 1; if x < 5 { a += 1; } }
45+
} else if x < 6 { a += 1; } }
46+
}
47+
48+
fn main() { f(3, 4); }

tests/pretty/hir-if-else.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//@ pretty-compare-only
2+
//@ pretty-mode:hir
3+
//@ pp-exact:hir-if-else.pp
4+
5+
fn f(x: u32, y: u32) {
6+
let mut a = 0;
7+
if x > y {
8+
a = 1;
9+
} else {
10+
a = 2;
11+
}
12+
13+
if x < 1 {
14+
a = 1;
15+
} else if x < 2 {
16+
a = 2;
17+
} else if x < 3 {
18+
a = 3;
19+
} else if x < 4 {
20+
a = 4;
21+
} else {
22+
a = 5;
23+
}
24+
25+
if x < y {
26+
a += 1;
27+
a += 1;
28+
a += 1;
29+
a += 1;
30+
a += 1;
31+
a += 1;
32+
} else {
33+
a += 1;
34+
a += 1;
35+
a += 1;
36+
a += 1;
37+
a += 1;
38+
a += 1;
39+
}
40+
41+
if x < 1 {
42+
if x < 2 {
43+
if x < 3 {
44+
a += 1;
45+
} else if x < 4 {
46+
a += 1;
47+
if x < 5 {
48+
a += 1;
49+
}
50+
}
51+
} else if x < 6 {
52+
a += 1;
53+
}
54+
}
55+
}
56+
57+
fn main() {
58+
f(3, 4);
59+
}

tests/pretty/if-else.pp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#![feature(prelude_import)]
2+
#![no_std]
3+
#[prelude_import]
4+
use ::std::prelude::rust_2015::*;
5+
#[macro_use]
6+
extern crate std;
7+
//@ pretty-compare-only
8+
//@ pretty-mode:expanded
9+
//@ pp-exact:if-else.pp
10+
11+
fn f(x: u32, y: u32) {
12+
let mut a = 0;
13+
if x > y { a = 1; } else { a = 2; }
14+
15+
if x < 1 {
16+
a = 1;
17+
} else if x < 2 {
18+
a = 2;
19+
} else if x < 3 { a = 3; } else if x < 4 { a = 4; } else { a = 5; }
20+
21+
if x < y {
22+
a += 1;
23+
a += 1;
24+
a += 1;
25+
} else {
26+
a += 1;
27+
a += 1;
28+
a += 1;
29+
a += 1;
30+
a += 1;
31+
a += 1;
32+
a += 1;
33+
a += 1;
34+
a += 1;
35+
a += 1;
36+
a += 1;
37+
a += 1;
38+
a += 1;
39+
a += 1;
40+
a += 1;
41+
}
42+
43+
if x < 1 {
44+
if x < 2 {
45+
if x < 3 {
46+
a += 1;
47+
} else if x < 4 { a += 1; if x < 5 { a += 1; } }
48+
} else if x < 6 { a += 1; }
49+
}
50+
}
51+
52+
fn main() { f(3, 4); }

tests/pretty/if-else.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//@ pretty-compare-only
2+
//@ pretty-mode:expanded
3+
//@ pp-exact:if-else.pp
4+
5+
fn f(x: u32, y: u32) {
6+
let mut a = 0;
7+
if x > y {
8+
a = 1;
9+
} else {
10+
a = 2;
11+
}
12+
13+
if x < 1 {
14+
a = 1;
15+
} else if x < 2 {
16+
a = 2;
17+
} else if x < 3 {
18+
a = 3;
19+
} else if x < 4 {
20+
a = 4;
21+
} else {
22+
a = 5;
23+
}
24+
25+
if x < y {
26+
a += 1;
27+
a += 1;
28+
a += 1;
29+
} else {
30+
a += 1;
31+
a += 1;
32+
a += 1;
33+
a += 1;
34+
a += 1;
35+
a += 1;
36+
a += 1;
37+
a += 1;
38+
a += 1;
39+
a += 1;
40+
a += 1;
41+
a += 1;
42+
a += 1;
43+
a += 1;
44+
a += 1;
45+
}
46+
47+
if x < 1 {
48+
if x < 2 {
49+
if x < 3 {
50+
a += 1;
51+
} else if x < 4 {
52+
a += 1;
53+
if x < 5 {
54+
a += 1;
55+
}
56+
}
57+
} else if x < 6 {
58+
a += 1;
59+
}
60+
}
61+
}
62+
63+
fn main() {
64+
f(3, 4);
65+
}

0 commit comments

Comments
 (0)