2 #![feature(format_args_capture)]
5 named_argument_takes_precedence_to_captured();
6 panic_with_single_argument_does_not_get_formatted();
7 panic_with_multiple_arguments_is_formatted();
8 formatting_parameters_can_be_captured();
11 fn named_argument_takes_precedence_to_captured() {
13 let s = format!("{foo}", foo="named");
14 assert_eq!(&s, "named");
16 let s = format!("{foo}-{foo}-{foo}", foo="named");
17 assert_eq!(&s, "named-named-named");
19 let s = format!("{}-{bar}-{foo}", "positional", bar="named");
20 assert_eq!(&s, "positional-named-captured");
23 fn panic_with_single_argument_does_not_get_formatted() {
24 // panic! with a single argument does not perform string formatting.
25 // RFC #2795 suggests that this may need to change so that captured arguments are formatted.
26 // For stability reasons this will need to part of an edition change.
28 let msg = std::panic::catch_unwind(|| {
32 assert_eq!(msg.downcast_ref::<&str>(), Some(&"{foo}"))
35 fn panic_with_multiple_arguments_is_formatted() {
38 let msg = std::panic::catch_unwind(|| {
39 panic!("{}-{bar}-{foo}", "positional", bar="named");
42 assert_eq!(msg.downcast_ref::<String>(), Some(&"positional-named-captured".to_string()))
45 fn formatting_parameters_can_be_captured() {
51 let s = format!("{x:width$}");
54 let s = format!("{x:<width$}");
57 let s = format!("{x:-^width$}");
58 assert_eq!(&s, "----7----");
60 let s = format!("{x:-^width$.precision$}");
61 assert_eq!(&s, "--7.000--");