X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2Ftest%2Frun-pass%2Fifmt.rs;h=2a7a593d26800fd322d77a2ede4ba29960089d44;hb=c30ab7b35a139eccf1c05c82b5b62b0decad3ca5;hp=27cafeacc203d73f5911dd7e88c59cc05270e9a0;hpb=54a0048b59ea495a22e43a2e9a5fadf6d5912c15;p=rustc.git diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 27cafeacc2..2a7a593d26 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -8,13 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// no-pretty-expanded unnecessary unsafe block generated - #![deny(warnings)] #![allow(unused_must_use)] #![allow(unused_features)] #![feature(box_syntax)] -#![feature(question_mark)] use std::fmt::{self, Write}; use std::usize; @@ -70,15 +67,15 @@ pub fn main() { t!(format!("{}", '☃'), "☃"); t!(format!("{}", 10), "10"); t!(format!("{}", 10_usize), "10"); - t!(format!("{:?}", '☃'), "'\\u{2603}'"); + t!(format!("{:?}", '☃'), "'☃'"); t!(format!("{:?}", 10), "10"); t!(format!("{:?}", 10_usize), "10"); t!(format!("{:?}", "true"), "\"true\""); t!(format!("{:?}", "foo\nbar"), "\"foo\\nbar\""); t!(format!("{:?}", "foo\n\"bar\"\r\n\'baz\'\t\\qux\\"), r#""foo\n\"bar\"\r\n\'baz\'\t\\qux\\""#); - t!(format!("{:?}", "foo\0bar\x01baz\u{3b1}q\u{75}x"), - r#""foo\u{0}bar\u{1}baz\u{3b1}qux""#); + t!(format!("{:?}", "foo\0bar\x01baz\u{7f}q\u{75}x"), + r#""foo\u{0}bar\u{1}baz\u{7f}qux""#); t!(format!("{:o}", 10_usize), "12"); t!(format!("{:x}", 10_usize), "a"); t!(format!("{:X}", 10_usize), "A"); @@ -125,7 +122,7 @@ pub fn main() { t!(format!("{:<4.4}", "aaaaaaaaaaaaaaaaaa"), "aaaa"); t!(format!("{:>4.4}", "aaaaaaaaaaaaaaaaaa"), "aaaa"); t!(format!("{:^4.4}", "aaaaaaaaaaaaaaaaaa"), "aaaa"); - t!(format!("{:>10.4}", "aaaaaaaaaaaaaaaaaa"), "aaaa"); + t!(format!("{:>10.4}", "aaaaaaaaaaaaaaaaaa"), " aaaa"); t!(format!("{:2.4}", "aaaaa"), "aaaa"); t!(format!("{:2.4}", "aaaa"), "aaaa"); t!(format!("{:2.4}", "aaa"), "aaa"); @@ -140,6 +137,7 @@ pub fn main() { t!(format!("{:a$}", "a", a=4), "a "); t!(format!("{:-#}", "a"), "a"); t!(format!("{:+#}", "a"), "a"); + t!(format!("{:/^10.8}", "1234567890"), "/12345678/"); // Some float stuff t!(format!("{:}", 1.0f32), "1"); @@ -163,6 +161,24 @@ pub fn main() { t!(format!("{:?}", 0.0), "0"); + // Ergonomic format_args! + t!(format!("{0:x} {0:X}", 15), "f F"); + t!(format!("{0:x} {0:X} {}", 15), "f F 15"); + // NOTE: For now the longer test cases must not be followed immediately by + // >1 empty lines, or the pretty printer will break. Since no one wants to + // touch the current pretty printer (#751), we have no choice but to work + // around it. Some of the following test cases are also affected. + t!(format!("{:x}{0:X}{a:x}{:X}{1:x}{a:X}", 13, 14, a=15), "dDfEeF"); + t!(format!("{a:x} {a:X}", a=15), "f F"); + + // And its edge cases + t!(format!("{a:.0$} {b:.0$} {0:.0$}\n{a:.c$} {b:.c$} {c:.c$}", + 4, a="abcdefg", b="hijklmn", c=3), + "abcd hijk 4\nabc hij 3"); + t!(format!("{a:.*} {0} {:.*}", 4, 3, "efgh", a="abcdef"), "abcd 4 efg"); + t!(format!("{:.a$} {a} {a:#x}", "aaaaaa", a=2), "aa 2 0x2"); + + // Test that pointers don't get truncated. { let val = usize::MAX; @@ -177,6 +193,7 @@ pub fn main() { test_write(); test_print(); test_order(); + test_once(); // make sure that format! doesn't move out of local variables let a: Box<_> = box 3; @@ -220,7 +237,7 @@ fn test_write() { // can do with them just yet (to test the output) fn test_print() { print!("hi"); - print!("{:?}", vec!(0u8)); + print!("{:?}", vec![0u8]); println!("hello"); println!("this is a {}", "test"); println!("{foo}", foo="bar"); @@ -260,3 +277,17 @@ fn test_order() { foo(), foo(), foo(), a=foo(), b=foo(), c=foo()), "1 2 4 5 3 6".to_string()); } + +fn test_once() { + // Make sure each argument are evaluted only once even though it may be + // formatted multiple times + fn foo() -> isize { + static mut FOO: isize = 0; + unsafe { + FOO += 1; + FOO + } + } + assert_eq!(format!("{0} {0} {0} {a} {a} {a}", foo(), a=foo()), + "1 1 1 2 2 2".to_string()); +}