Skip to content

Commit 36cb387

Browse files
Kivooeotgross35
authored andcommitted
moved renamed docs formatted | log-knows-the-names-of-variants.rs
1 parent ebc2aef commit 36cb387

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
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

1716
pub 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
}

0 commit comments

Comments
 (0)