about summary refs log tree commit diff
path: root/src/test/compile-fail
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-07-29 01:12:41 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-08-07 19:21:43 -0700
commitffb670ffcd69ed8e7cd13a7f06375ede752349e2 (patch)
treea3e82ac51c713a80d620128813b4fa653451da97 /src/test/compile-fail
parent5b4244d917cc9341b1ec04c4e245d5f841d3facc (diff)
downloadrust-ffb670ffcd69ed8e7cd13a7f06375ede752349e2.tar.gz
rust-ffb670ffcd69ed8e7cd13a7f06375ede752349e2.zip
Add initial support for a new formatting syntax
The new macro is available under the name ifmt! (only an intermediate name)
Diffstat (limited to 'src/test/compile-fail')
-rw-r--r--src/test/compile-fail/ifmt-bad-arg.rs74
-rw-r--r--src/test/compile-fail/ifmt-bad-plural.rs14
-rw-r--r--src/test/compile-fail/ifmt-bad-select.rs14
-rw-r--r--src/test/compile-fail/ifmt-unimpl.rs14
-rw-r--r--src/test/compile-fail/ifmt-unknown-trait.rs14
5 files changed, 130 insertions, 0 deletions
diff --git a/src/test/compile-fail/ifmt-bad-arg.rs b/src/test/compile-fail/ifmt-bad-arg.rs
new file mode 100644
index 00000000000..875ad0d2b62
--- /dev/null
+++ b/src/test/compile-fail/ifmt-bad-arg.rs
@@ -0,0 +1,74 @@
+// 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() {
+    // bad arguments to the ifmt! call
+
+    ifmt!();                //~ ERROR: expects at least one
+    ifmt!("{}");            //~ ERROR: invalid reference to argument
+
+    ifmt!("{1}", 1);        //~ ERROR: invalid reference to argument `1`
+                            //~^ ERROR: argument never used
+    ifmt!("{foo}");         //~ ERROR: no argument named `foo`
+
+    ifmt!("{}", 1, 2);               //~ ERROR: argument never used
+    ifmt!("{1}", 1, 2);              //~ ERROR: argument never used
+    ifmt!("{}", 1, foo=2);           //~ ERROR: named argument never used
+    ifmt!("{foo}", 1, foo=2);        //~ ERROR: argument never used
+    ifmt!("", foo=2);                //~ ERROR: named argument never used
+
+    ifmt!("{0:d} {0:s}", 1);         //~ ERROR: redeclared with type `s`
+    ifmt!("{foo:d} {foo:s}", foo=1); //~ ERROR: redeclared with type `s`
+
+    ifmt!("{foo}", foo=1, foo=2);    //~ ERROR: duplicate argument
+    ifmt!("#");                      //~ ERROR: `#` reference used
+    ifmt!("", foo=1, 2);             //~ ERROR: positional arguments cannot follow
+    ifmt!("" 1);                     //~ ERROR: expected token: `,`
+    ifmt!("", 1 1);                  //~ ERROR: expected token: `,`
+
+    ifmt!("{0, select, a{} a{} other{}}", "a");    //~ ERROR: duplicate selector
+    ifmt!("{0, plural, =1{} =1{} other{}}", 1u);   //~ ERROR: duplicate selector
+    ifmt!("{0, plural, one{} one{} other{}}", 1u); //~ ERROR: duplicate selector
+
+    // bad syntax of the format string
+
+    ifmt!("{"); //~ ERROR: unterminated format string
+    ifmt!("\\ "); //~ ERROR: invalid escape
+    ifmt!("\\"); //~ ERROR: expected an escape
+
+    ifmt!("{0, }", 1); //~ ERROR: expected method
+    ifmt!("{0, foo}", 1); //~ ERROR: unknown method
+    ifmt!("{0, select}", "a"); //~ ERROR: must be followed by
+    ifmt!("{0, plural}", 1); //~ ERROR: must be followed by
+
+    ifmt!("{0, select, a{{}", 1); //~ ERROR: must be terminated
+    ifmt!("{0, select, {} other{}}", "a"); //~ ERROR: empty selector
+    ifmt!("{0, select, other{} other{}}", "a"); //~ ERROR: multiple `other`
+    ifmt!("{0, plural, offset: other{}}", "a"); //~ ERROR: must be an integer
+    ifmt!("{0, plural, offset 1 other{}}", "a"); //~ ERROR: be followed by `:`
+    ifmt!("{0, plural, =a{} other{}}", "a"); //~ ERROR: followed by an integer
+    ifmt!("{0, plural, a{} other{}}", "a"); //~ ERROR: unexpected plural
+    ifmt!("{0, select, a{}}", "a"); //~ ERROR: must provide an `other`
+    ifmt!("{0, plural, =1{}}", "a"); //~ ERROR: must provide an `other`
+
+    ifmt!("{0, plural, other{{0:s}}}", "a"); //~ ERROR: previously used as
+    ifmt!("{:s} {0, plural, other{}}", "a"); //~ ERROR: argument used to
+    ifmt!("{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.
+    ifmt!("{0, select, other{{}}}", "a"); //~ ERROR: cannot use implicit
+    ifmt!("{0, plural, other{{}}}", 1); //~ ERROR: cannot use implicit
+    ifmt!("{0, plural, other{{1:.*d}}}", 1, 2); //~ ERROR: cannot use implicit
+}
diff --git a/src/test/compile-fail/ifmt-bad-plural.rs b/src/test/compile-fail/ifmt-bad-plural.rs
new file mode 100644
index 00000000000..76a697b174f
--- /dev/null
+++ b/src/test/compile-fail/ifmt-bad-plural.rs
@@ -0,0 +1,14 @@
+// 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() {
+    ifmt!("{0, plural, other{}}", "a");
+    //~^ ERROR: expected uint but found
+}
diff --git a/src/test/compile-fail/ifmt-bad-select.rs b/src/test/compile-fail/ifmt-bad-select.rs
new file mode 100644
index 00000000000..abe3b6ed65a
--- /dev/null
+++ b/src/test/compile-fail/ifmt-bad-select.rs
@@ -0,0 +1,14 @@
+// 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() {
+    ifmt!("{0, select, other{}}", 2);
+    //~^ ERROR: expected &str but found integral
+}
diff --git a/src/test/compile-fail/ifmt-unimpl.rs b/src/test/compile-fail/ifmt-unimpl.rs
new file mode 100644
index 00000000000..427f5ea562c
--- /dev/null
+++ b/src/test/compile-fail/ifmt-unimpl.rs
@@ -0,0 +1,14 @@
+// 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() {
+    ifmt!("{:d}", "3");
+    //~^ ERROR: failed to find an implementation of trait std::fmt::Signed
+}
diff --git a/src/test/compile-fail/ifmt-unknown-trait.rs b/src/test/compile-fail/ifmt-unknown-trait.rs
new file mode 100644
index 00000000000..85556f9501a
--- /dev/null
+++ b/src/test/compile-fail/ifmt-unknown-trait.rs
@@ -0,0 +1,14 @@
+// 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() {
+    ifmt!("{:notimplemented}", "3");
+    //~^ ERROR: unknown format trait `notimplemented`
+}