Skip to content

Commit 8ccaa83

Browse files
author
Michael Recachinas
committed
Add more tests to print_ and write_literal
Also, move precision, width, and debug fmt tests to 'should pass'
1 parent c5b39a5 commit 8ccaa83

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

tests/ui/print_literal.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,23 @@ fn main() {
99
let world = "world";
1010
println!("Hello {}", world);
1111
println!("3 in hex is {:X}", 3);
12+
println!("2 + 1 = {:.4}", 3);
13+
println!("2 + 1 = {:5.4}", 3);
14+
println!("Debug test {:?}", "hello, world");
15+
println!("{0:8} {1:>8}", "hello", "world");
16+
println!("{1:8} {0:>8}", "hello", "world");
17+
println!("{foo:8} {bar:>8}", foo="hello", bar="world");
18+
println!("{bar:8} {foo:>8}", foo="hello", bar="world");
19+
println!("{number:>width$}", number=1, width=6);
20+
println!("{number:>0width$}", number=1, width=6);
1221

1322
// these should throw warnings
23+
println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
1424
print!("Hello {}", "world");
1525
println!("Hello {} {}", world, "world");
1626
println!("Hello {}", "world");
1727
println!("10 / 4 is {}", 2.5);
1828
println!("2 + 1 = {}", 3);
19-
println!("2 + 1 = {:.4}", 3);
20-
println!("2 + 1 = {:5.4}", 3);
21-
println!("Debug test {:?}", "hello, world");
2229

2330
// positional args don't change the fact
2431
// that we're using a literal -- this should

tests/ui/write_literal.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,29 @@ use std::io::Write;
66
fn main() {
77
let mut v = Vec::new();
88

9-
// These should be fine
9+
// these should be fine
1010
write!(&mut v, "Hello");
1111
writeln!(&mut v, "Hello");
1212
let world = "world";
1313
writeln!(&mut v, "Hello {}", world);
1414
writeln!(&mut v, "3 in hex is {:X}", 3);
15+
writeln!(&mut v, "2 + 1 = {:.4}", 3);
16+
writeln!(&mut v, "2 + 1 = {:5.4}", 3);
17+
writeln!(&mut v, "Debug test {:?}", "hello, world");
18+
writeln!(&mut v, "{0:8} {1:>8}", "hello", "world");
19+
writeln!(&mut v, "{1:8} {0:>8}", "hello", "world");
20+
writeln!(&mut v, "{foo:8} {bar:>8}", foo="hello", bar="world");
21+
writeln!(&mut v, "{bar:8} {foo:>8}", foo="hello", bar="world");
22+
writeln!(&mut v, "{number:>width$}", number=1, width=6);
23+
writeln!(&mut v, "{number:>0width$}", number=1, width=6);
1524

16-
// These should throw warnings
25+
// these should throw warnings
26+
writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
1727
write!(&mut v, "Hello {}", "world");
1828
writeln!(&mut v, "Hello {} {}", world, "world");
1929
writeln!(&mut v, "Hello {}", "world");
2030
writeln!(&mut v, "10 / 4 is {}", 2.5);
2131
writeln!(&mut v, "2 + 1 = {}", 3);
22-
writeln!(&mut v, "2 + 1 = {:.4}", 3);
23-
writeln!(&mut v, "2 + 1 = {:5.4}", 3);
24-
writeln!(&mut v, "Debug test {:?}", "hello, world");
2532

2633
// positional args don't change the fact
2734
// that we're using a literal -- this should
@@ -30,6 +37,6 @@ fn main() {
3037
writeln!(&mut v, "{1} {0}", "hello", "world");
3138

3239
// named args shouldn't change anything either
33-
writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world");
34-
writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world");
40+
writeln!(&mut v, "{foo} {bar}", foo="hello", bar="world");
41+
writeln!(&mut v, "{bar} {foo}", foo="hello", bar="world");
3542
}

0 commit comments

Comments
 (0)