]> git.lizzy.rs Git - rust.git/blobdiff - src/test/run-pass/ifmt.rs
auto merge of #9140 : alexcrichton/rust/issue-9119, r=huonw
[rust.git] / src / test / run-pass / ifmt.rs
index 0b2203be9d7c0d582e4f454370eb1911225381dd..351bad193da2dfc85249039f122df30e7a2241c2 100644 (file)
 #[deny(warnings)];
 
 use std::fmt;
+use std::rt::io::Decorator;
+use std::rt::io::mem::MemWriter;
+use std::rt::io;
+use std::rt::io::Writer;
+use std::str;
 
 struct A;
 struct B;
@@ -236,16 +241,13 @@ pub fn main() {
         let a: int = ::std::cast::transmute(3u);
         format!("{}", a);
     }
+
+    test_format_args();
 }
 
 // Basic test to make sure that we can invoke the `write!` macro with an
 // io::Writer instance.
 fn test_write() {
-    use std::rt::io::Decorator;
-    use std::rt::io::mem::MemWriter;
-    use std::rt::io;
-    use std::str;
-
     let mut buf = MemWriter::new();
     write!(&mut buf as &mut io::Writer, "{}", 3);
     {
@@ -269,3 +271,20 @@ fn test_print() {
     println!("this is a {}", "test");
     println!("{foo}", foo="bar");
 }
+
+// Just make sure that the macros are defined, there's not really a lot that we
+// can do with them just yet (to test the output)
+fn test_format_args() {
+    let mut buf = MemWriter::new();
+    {
+        let w = &mut buf as &mut io::Writer;
+        format_args!(|args| { fmt::write(w, args) }, "{}", 1);
+        format_args!(|args| { fmt::write(w, args) }, "test");
+        format_args!(|args| { fmt::write(w, args) }, "{test}", test=3);
+    }
+    let s = str::from_utf8_owned(buf.inner());
+    t!(s, "1test3");
+
+    let s = format_args!(fmt::format, "hello {}", "world");
+    t!(s, "hello world");
+}