]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/fmt/format-args-capture.rs
2 #![feature(format_args_capture)]
6 named_argument_takes_precedence_to_captured();
7 formatting_parameters_can_be_captured();
8 capture_raw_strings_and_idents();
10 #[cfg(panic = "unwind")]
12 panic_with_single_argument_does_not_get_formatted();
13 panic_with_multiple_arguments_is_formatted();
17 fn named_argument_takes_precedence_to_captured() {
19 let s
= format
!("{foo}", foo
= "named");
20 assert_eq
!(&s
, "named");
22 let s
= format
!("{foo}-{foo}-{foo}", foo
= "named");
23 assert_eq
!(&s
, "named-named-named");
25 let s
= format
!("{}-{bar}-{foo}", "positional", bar
= "named");
26 assert_eq
!(&s
, "positional-named-captured");
29 fn capture_raw_strings_and_idents() {
31 let s
= format
!(r
#"The fruit is an {type}"#);
32 assert_eq
!(&s
, "The fruit is an apple");
34 let r
#type = "orange";
35 let s
= format
!(r
"The fruit is an {type}");
36 assert_eq
!(&s
, "The fruit is an orange");
39 #[cfg(panic = "unwind")]
40 fn panic_with_single_argument_does_not_get_formatted() {
41 // panic! with a single argument does not perform string formatting.
42 // RFC #2795 suggests that this may need to change so that captured arguments are formatted.
43 // For stability reasons this will need to part of an edition change.
45 #[allow(non_fmt_panics)]
46 let msg
= std
::panic
::catch_unwind(|| {
51 assert_eq
!(msg
.downcast_ref
::<&str>(), Some(&"{foo}"))
54 #[cfg(panic = "unwind")]
55 fn panic_with_multiple_arguments_is_formatted() {
58 let msg
= std
::panic
::catch_unwind(|| {
59 panic
!("{}-{bar}-{foo}", "positional", bar
= "named");
63 assert_eq
!(msg
.downcast_ref
::<String
>(), Some(&"positional-named-captured".to_string()))
66 fn formatting_parameters_can_be_captured() {
72 let s
= format
!("{x:width$}");
75 let s
= format
!("{x:<width$}");
78 let s
= format
!("{x:-^width$}");
79 assert_eq
!(&s
, "----7----");
81 let s
= format
!("{x:-^width$.precision$}");
82 assert_eq
!(&s
, "--7.000--");