1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 // bad arguments to the ifmt! call
14 ifmt!(); //~ ERROR: expects at least one
15 ifmt!("{}"); //~ ERROR: invalid reference to argument
17 ifmt!("{1}", 1); //~ ERROR: invalid reference to argument `1`
18 //~^ ERROR: argument never used
19 ifmt!("{foo}"); //~ ERROR: no argument named `foo`
21 ifmt!("{}", 1, 2); //~ ERROR: argument never used
22 ifmt!("{1}", 1, 2); //~ ERROR: argument never used
23 ifmt!("{}", 1, foo=2); //~ ERROR: named argument never used
24 ifmt!("{foo}", 1, foo=2); //~ ERROR: argument never used
25 ifmt!("", foo=2); //~ ERROR: named argument never used
27 ifmt!("{0:d} {0:s}", 1); //~ ERROR: redeclared with type `s`
28 ifmt!("{foo:d} {foo:s}", foo=1); //~ ERROR: redeclared with type `s`
30 ifmt!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument
31 ifmt!("#"); //~ ERROR: `#` reference used
32 ifmt!("", foo=1, 2); //~ ERROR: positional arguments cannot follow
33 ifmt!("" 1); //~ ERROR: expected token: `,`
34 ifmt!("", 1 1); //~ ERROR: expected token: `,`
36 ifmt!("{0, select, a{} a{} other{}}", "a"); //~ ERROR: duplicate selector
37 ifmt!("{0, plural, =1{} =1{} other{}}", 1u); //~ ERROR: duplicate selector
38 ifmt!("{0, plural, one{} one{} other{}}", 1u); //~ ERROR: duplicate selector
40 // bad syntax of the format string
42 ifmt!("{"); //~ ERROR: unterminated format string
43 ifmt!("\\ "); //~ ERROR: invalid escape
44 ifmt!("\\"); //~ ERROR: expected an escape
46 ifmt!("{0, }", 1); //~ ERROR: expected method
47 ifmt!("{0, foo}", 1); //~ ERROR: unknown method
48 ifmt!("{0, select}", "a"); //~ ERROR: must be followed by
49 ifmt!("{0, plural}", 1); //~ ERROR: must be followed by
51 ifmt!("{0, select, a{{}", 1); //~ ERROR: must be terminated
52 ifmt!("{0, select, {} other{}}", "a"); //~ ERROR: empty selector
53 ifmt!("{0, select, other{} other{}}", "a"); //~ ERROR: multiple `other`
54 ifmt!("{0, plural, offset: other{}}", "a"); //~ ERROR: must be an integer
55 ifmt!("{0, plural, offset 1 other{}}", "a"); //~ ERROR: be followed by `:`
56 ifmt!("{0, plural, =a{} other{}}", "a"); //~ ERROR: followed by an integer
57 ifmt!("{0, plural, a{} other{}}", "a"); //~ ERROR: unexpected plural
58 ifmt!("{0, select, a{}}", "a"); //~ ERROR: must provide an `other`
59 ifmt!("{0, plural, =1{}}", "a"); //~ ERROR: must provide an `other`
61 ifmt!("{0, plural, other{{0:s}}}", "a"); //~ ERROR: previously used as
62 ifmt!("{:s} {0, plural, other{}}", "a"); //~ ERROR: argument used to
63 ifmt!("{0, select, other{}} \
64 {0, plural, other{}}", "a");
65 //~^ ERROR: declared with multiple formats
67 // It should be illegal to use implicit placement arguments nested inside of
68 // format strings because otherwise the "internal pointer of which argument
69 // is next" would be invalidated if different cases had different numbers of
71 ifmt!("{0, select, other{{}}}", "a"); //~ ERROR: cannot use implicit
72 ifmt!("{0, plural, other{{}}}", 1); //~ ERROR: cannot use implicit
73 ifmt!("{0, plural, other{{1:.*d}}}", 1, 2); //~ ERROR: cannot use implicit