File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change 1+ //! Test that `#[derive(Debug)]` for enums correctly formats variant names.
2+
13//@ run-pass
24
3- #![ allow( non_camel_case_types) ]
4- #![ allow( dead_code) ]
55#[ derive( Debug ) ]
6- enum foo {
7- a( usize ) ,
8- b( String ) ,
9- c,
6+ enum Foo {
7+ A ( usize ) ,
8+ C ,
109}
1110
1211#[ derive( Debug ) ]
13- enum bar {
14- d , e , f
12+ enum Bar {
13+ D ,
1514}
1615
1716pub fn main ( ) {
18- assert_eq ! ( "a(22)" . to_string( ) , format!( "{:?}" , foo:: a( 22 ) ) ) ;
19- assert_eq ! ( "c" . to_string( ) , format!( "{:?}" , foo:: c) ) ;
20- assert_eq ! ( "d" . to_string( ) , format!( "{:?}" , bar:: d) ) ;
17+ // Test variant with data
18+ let foo_a = Foo :: A ( 22 ) ;
19+ assert_eq ! ( "A(22)" . to_string( ) , format!( "{:?}" , foo_a) ) ;
20+
21+ if let Foo :: A ( value) = foo_a {
22+ println ! ( "Value: {}" , value) ; // This needs to remove #[allow(dead_code)]
23+ }
24+
25+ // Test unit variant
26+ assert_eq ! ( "C" . to_string( ) , format!( "{:?}" , Foo :: C ) ) ;
27+
28+ // Test unit variant from different enum
29+ assert_eq ! ( "D" . to_string( ) , format!( "{:?}" , Bar :: D ) ) ;
2130}
You can’t perform that action at this time.
0 commit comments