auto merge of #14831 : alexcrichton/rust/format-intl, r=brson
* The select/plural methods from format strings are removed
* The # character no longer needs to be escaped
* The \-based escapes have been removed
* '{{' is now an escape for '{'
* '}}' is now an escape for '}'
Closes #14810
[breaking-change]
This commit is contained in:
commit
0422934e24
57 changed files with 736 additions and 1087 deletions
|
|
@ -27,47 +27,11 @@ fn main() {
|
|||
format!("{foo:d} {foo:s}", foo=1); //~ ERROR: redeclared with type `s`
|
||||
|
||||
format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument
|
||||
format!("#"); //~ ERROR: `#` reference used
|
||||
format!("", foo=1, 2); //~ ERROR: positional arguments cannot follow
|
||||
|
||||
format!("{0, select, a{} a{} other{}}", "a"); //~ ERROR: duplicate selector
|
||||
format!("{0, plural, =1{} =1{} other{}}", 1u); //~ ERROR: duplicate selector
|
||||
format!("{0, plural, one{} one{} other{}}", 1u); //~ ERROR: duplicate selector
|
||||
|
||||
// bad syntax of the format string
|
||||
|
||||
format!("{"); //~ ERROR: expected `}` but string was terminated
|
||||
format!("\\ "); //~ ERROR: invalid escape
|
||||
format!("\\"); //~ ERROR: expected an escape
|
||||
|
||||
format!("{0, }", 1); //~ ERROR: expected method
|
||||
format!("{0, foo}", 1); //~ ERROR: unknown method
|
||||
format!("{0, select}", "a"); //~ ERROR: expected `,` but found `}`
|
||||
format!("{0, plural}", 1); //~ ERROR: expected `,` but found `}`
|
||||
|
||||
format!("{0, select, a{{}", 1); //~ ERROR: expected `}` but string was terminated
|
||||
format!("{0, select, {} other{}}", "a"); //~ ERROR: empty selector
|
||||
format!("{0, select, other{} other{}}", "a"); //~ ERROR: multiple `other`
|
||||
format!("{0, plural, offset: other{}}", "a"); //~ ERROR: must be an integer
|
||||
format!("{0, plural, offset 1 other{}}", "a"); //~ ERROR: expected `:` but found `1`
|
||||
format!("{0, plural, =a{} other{}}", "a"); //~ ERROR: followed by an integer
|
||||
format!("{0, plural, a{} other{}}", "a"); //~ ERROR: unexpected plural
|
||||
format!("{0, select, a{}}", "a"); //~ ERROR: must provide an `other`
|
||||
format!("{0, plural, =1{}}", "a"); //~ ERROR: must provide an `other`
|
||||
|
||||
format!("{0, plural, other{{0:s}}}", "a"); //~ ERROR: previously used as
|
||||
format!("{:s} {0, plural, other{}}", "a"); //~ ERROR: argument used to
|
||||
format!("{0, select, other{}} \
|
||||
{0, plural, other{}}", "a");
|
||||
//~^ ERROR: declared with multiple formats
|
||||
|
||||
// It should be illegal to use implicit placement arguments nested inside of
|
||||
// format strings because otherwise the "internal pointer of which argument
|
||||
// is next" would be invalidated if different cases had different numbers of
|
||||
// arguments.
|
||||
format!("{1, select, other{{}}}", 1, "a"); //~ ERROR: cannot use implicit
|
||||
format!("{1, plural, other{{}}}", 1, 1); //~ ERROR: cannot use implicit
|
||||
format!("{0, plural, other{{1:.*d}}}", 1, 2); //~ ERROR: cannot use implicit
|
||||
|
||||
format!("foo } bar"); //~ ERROR: unmatched `}` found
|
||||
format!("foo }"); //~ ERROR: unmatched `}` found
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
format!("{0, plural, other{}}", "a");
|
||||
//~^ ERROR: expected uint but found
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
format!("{0, select, other{}}", 2);
|
||||
//~^ ERROR: mismatched types: expected `&&str` but found `&<generic integer #0>` (expected &-ptr
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ fn main() {
|
|||
|
||||
{
|
||||
let _ = write!(&mut File::create(&main_file).unwrap(),
|
||||
r"\#![feature(non_ascii_idents)] fn main() \{ {} \}",
|
||||
"#![feature(non_ascii_idents)] fn main() {{ {} }}",
|
||||
// random string of length n
|
||||
range(0, n).map(|_| random_char()).collect::<String>());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ static y: &'static Pair<'static> = &Pair {a: 15, b: x};
|
|||
|
||||
pub fn main() {
|
||||
println!("x = {}", *x);
|
||||
println!("y = \\{a: {}, b: {}\\}", y.a, *(y.b));
|
||||
println!("y = {{a: {}, b: {}}}", y.a, *(y.b));
|
||||
assert_eq!(*x, 10);
|
||||
assert_eq!(*(y.b), 10);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![deny(non_uppercase_statics)]
|
||||
|
||||
pub fn main() {
|
||||
println!("I generate statics with {0, select, other{#}}", "weird names");
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ pub fn main() {
|
|||
// Various edge cases without formats
|
||||
t!(format!(""), "");
|
||||
t!(format!("hello"), "hello");
|
||||
t!(format!("hello \\{"), "hello {");
|
||||
t!(format!("hello {{"), "hello {");
|
||||
|
||||
// default formatters should work
|
||||
t!(format!("{}", 1.0f32), "1");
|
||||
|
|
@ -80,18 +80,6 @@ pub fn main() {
|
|||
t!(format!("{foo_bar}", foo_bar=1), "1");
|
||||
t!(format!("{:d}", 5 + 5), "10");
|
||||
|
||||
// Methods should probably work
|
||||
t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 0u), "c0");
|
||||
t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 1u), "a1");
|
||||
t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 2u), "b2");
|
||||
t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 3u), "d3");
|
||||
t!(format!("{0, select, a{a#} b{b#} c{c#} other{d#}}", "a"), "aa");
|
||||
t!(format!("{0, select, a{a#} b{b#} c{c#} other{d#}}", "b"), "bb");
|
||||
t!(format!("{0, select, a{a#} b{b#} c{c#} other{d#}}", "c"), "cc");
|
||||
t!(format!("{0, select, a{a#} b{b#} c{c#} other{d#}}", "d"), "dd");
|
||||
t!(format!("{1, select, a{#{0:s}} other{#}}", "b", "a"), "ab");
|
||||
t!(format!("{1, select, a{#{0}} other{#}}", "c", "b"), "b");
|
||||
|
||||
// Formatting strings and their arguments
|
||||
t!(format!("{:s}", "a"), "a");
|
||||
t!(format!("{:4s}", "a"), "a ");
|
||||
|
|
@ -135,10 +123,8 @@ pub fn main() {
|
|||
t!(format!("{:+10.3e}", -1.2345e6f64), " -1.234e6");
|
||||
|
||||
// Escaping
|
||||
t!(format!("\\{"), "{");
|
||||
t!(format!("\\}"), "}");
|
||||
t!(format!("\\#"), "#");
|
||||
t!(format!("\\\\"), "\\");
|
||||
t!(format!("{{"), "{");
|
||||
t!(format!("}}"), "}");
|
||||
|
||||
test_write();
|
||||
test_print();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ struct Thingy {
|
|||
|
||||
impl fmt::Show for Thingy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "\\{ x: {}, y: {} \\}", self.x, self.y)
|
||||
write!(f, "{{ x: {}, y: {} }}", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue