diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-04-25 12:25:04 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-04-25 14:33:14 +1000 |
| commit | 3d488f8e0c953f10852431f4c195e6b24cc6eec7 (patch) | |
| tree | c204447e053222f761bed72fc3482899da3a0dda /tests/pretty | |
| parent | dc8fe1f81c6cf13c0987944c525b2aa81625b5d0 (diff) | |
| download | rust-3d488f8e0c953f10852431f4c195e6b24cc6eec7.tar.gz rust-3d488f8e0c953f10852431f4c195e6b24cc6eec7.zip | |
Add pretty printing tests for if/else.
The AST pretty printing is a bit wonky. The HIR pretty printing is extremely wonky.
Diffstat (limited to 'tests/pretty')
| -rw-r--r-- | tests/pretty/hir-if-else.pp | 48 | ||||
| -rw-r--r-- | tests/pretty/hir-if-else.rs | 59 | ||||
| -rw-r--r-- | tests/pretty/if-else.pp | 52 | ||||
| -rw-r--r-- | tests/pretty/if-else.rs | 65 |
4 files changed, 224 insertions, 0 deletions
diff --git a/tests/pretty/hir-if-else.pp b/tests/pretty/hir-if-else.pp new file mode 100644 index 00000000000..551f24c6900 --- /dev/null +++ b/tests/pretty/hir-if-else.pp @@ -0,0 +1,48 @@ +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +//@ pretty-compare-only +//@ pretty-mode:hir +//@ pp-exact:hir-if-else.pp + +fn f(x: u32, + y: + u32) { + let mut a = 0; + if x > y { a = 1; } else { a = 2; } + + if x < 1 + { + a = 1; + } else if x < 2 + { + a = 2; + } else if x < 3 + { + a = 3; + } else if x < 4 { a = 4; } else { a = 5; } + + if x < y + { + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + } else { a += 1; a += 1; a += 1; a += 1; a += 1; a += 1; } + + if x < 1 + { + if x < 2 + { + if x < 3 + { + a += 1; + } else if x < 4 + { a += 1; if x < 5 { a += 1; } } + } else if x < 6 { a += 1; } } + } + + fn main() { f(3, 4); } diff --git a/tests/pretty/hir-if-else.rs b/tests/pretty/hir-if-else.rs new file mode 100644 index 00000000000..a1cc7504f89 --- /dev/null +++ b/tests/pretty/hir-if-else.rs @@ -0,0 +1,59 @@ +//@ pretty-compare-only +//@ pretty-mode:hir +//@ pp-exact:hir-if-else.pp + +fn f(x: u32, y: u32) { + let mut a = 0; + if x > y { + a = 1; + } else { + a = 2; + } + + if x < 1 { + a = 1; + } else if x < 2 { + a = 2; + } else if x < 3 { + a = 3; + } else if x < 4 { + a = 4; + } else { + a = 5; + } + + if x < y { + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + } else { + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + } + + if x < 1 { + if x < 2 { + if x < 3 { + a += 1; + } else if x < 4 { + a += 1; + if x < 5 { + a += 1; + } + } + } else if x < 6 { + a += 1; + } + } +} + +fn main() { + f(3, 4); +} diff --git a/tests/pretty/if-else.pp b/tests/pretty/if-else.pp new file mode 100644 index 00000000000..c70a78ade42 --- /dev/null +++ b/tests/pretty/if-else.pp @@ -0,0 +1,52 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +//@ pretty-compare-only +//@ pretty-mode:expanded +//@ pp-exact:if-else.pp + +fn f(x: u32, y: u32) { + let mut a = 0; + if x > y { a = 1; } else { a = 2; } + + if x < 1 { + a = 1; + } else if x < 2 { + a = 2; + } else if x < 3 { a = 3; } else if x < 4 { a = 4; } else { a = 5; } + + if x < y { + a += 1; + a += 1; + a += 1; + } else { + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + } + + if x < 1 { + if x < 2 { + if x < 3 { + a += 1; + } else if x < 4 { a += 1; if x < 5 { a += 1; } } + } else if x < 6 { a += 1; } + } +} + +fn main() { f(3, 4); } diff --git a/tests/pretty/if-else.rs b/tests/pretty/if-else.rs new file mode 100644 index 00000000000..b4085ea5606 --- /dev/null +++ b/tests/pretty/if-else.rs @@ -0,0 +1,65 @@ +//@ pretty-compare-only +//@ pretty-mode:expanded +//@ pp-exact:if-else.pp + +fn f(x: u32, y: u32) { + let mut a = 0; + if x > y { + a = 1; + } else { + a = 2; + } + + if x < 1 { + a = 1; + } else if x < 2 { + a = 2; + } else if x < 3 { + a = 3; + } else if x < 4 { + a = 4; + } else { + a = 5; + } + + if x < y { + a += 1; + a += 1; + a += 1; + } else { + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + } + + if x < 1 { + if x < 2 { + if x < 3 { + a += 1; + } else if x < 4 { + a += 1; + if x < 5 { + a += 1; + } + } + } else if x < 6 { + a += 1; + } + } +} + +fn main() { + f(3, 4); +} |
