diff options
| author | Tommy Ip <hkmp7tommy@gmail.com> | 2017-11-06 14:20:15 +0000 |
|---|---|---|
| committer | Tommy Ip <hkmp7tommy@gmail.com> | 2017-11-06 16:28:30 +0000 |
| commit | d5cb474f5761fd80b5d7ab7d43671dfbd534acce (patch) | |
| tree | e659390f4fbbd0ee3d863d66485e6d97ff3811fb | |
| parent | 82d5ea4b12d8543c6c8f871881fbbefbf5e63dc2 (diff) | |
| download | rust-d5cb474f5761fd80b5d7ab7d43671dfbd534acce.tar.gz rust-d5cb474f5761fd80b5d7ab7d43671dfbd534acce.zip | |
Add tests for new format! error message
| -rw-r--r-- | src/test/compile-fail/ifmt-bad-arg.rs | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/src/test/compile-fail/ifmt-bad-arg.rs b/src/test/compile-fail/ifmt-bad-arg.rs index a23b4b07741..336a0d825cb 100644 --- a/src/test/compile-fail/ifmt-bad-arg.rs +++ b/src/test/compile-fail/ifmt-bad-arg.rs @@ -11,36 +11,39 @@ fn main() { // bad arguments to the format! call - format!("{}"); //~ ERROR: invalid reference to argument + // bad number of arguments, see #44954 (originally #15780) - format!("{1}", 1); //~ ERROR: invalid reference to argument `1` - //~^ ERROR: argument never used - format!("{foo}"); //~ ERROR: no argument named `foo` + format!("{}"); + //~^ ERROR: 1 positional argument in format string, but no arguments were given - format!("", 1, 2); //~ ERROR: multiple unused formatting arguments - format!("{}", 1, 2); //~ ERROR: argument never used - format!("{1}", 1, 2); //~ ERROR: argument never used - format!("{}", 1, foo=2); //~ ERROR: named argument never used - format!("{foo}", 1, foo=2); //~ ERROR: argument never used - format!("", foo=2); //~ ERROR: named argument never used + format!("{1}", 1); + //~^ ERROR: 1 positional argument in format string, but there is only 1 argument + //~^^ ERROR: argument never used - format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument - format!("", foo=1, 2); //~ ERROR: positional arguments cannot follow - - // bad number of arguments, see #15780 - - format!("{0}"); - //~^ ERROR invalid reference to argument `0` (no arguments given) + format!("{} {}"); + //~^ ERROR: 2 positional arguments in format string, but no arguments were given format!("{0} {1}", 1); - //~^ ERROR invalid reference to argument `1` (there is 1 argument) + //~^ ERROR: 2 positional arguments in format string, but there is only 1 argument format!("{0} {1} {2}", 1, 2); - //~^ ERROR invalid reference to argument `2` (there are 2 arguments) - - format!("{0} {1}"); - //~^ ERROR invalid reference to argument `0` (no arguments given) - //~^^ ERROR invalid reference to argument `1` (no arguments given) + //~^ ERROR: 3 positional arguments in format string, but there are only 2 arguments + + format!("{} {value} {} {}", 1, value=2); + //~^ ERROR: invalid reference to positional argument 2 (there are only 2 arguments) + format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2); + //~^ ERROR: invalid reference to positional arguments 3, 4 and 5 (there are only 3 arguments) + + format!("{foo}"); //~ ERROR: no argument named `foo` + format!("", 1, 2); //~ ERROR: multiple unused formatting arguments + format!("{}", 1, 2); //~ ERROR: argument never used + format!("{1}", 1, 2); //~ ERROR: argument never used + format!("{}", 1, foo=2); //~ ERROR: named argument never used + format!("{foo}", 1, foo=2); //~ ERROR: argument never used + format!("", foo=2); //~ ERROR: named argument never used + + format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument + format!("", foo=1, 2); //~ ERROR: positional arguments cannot follow // bad named arguments, #35082 |
