MCPcopy Create free account
hub / github.com/bitflags/bitflags / cases

Function cases

src/tests/flag_name.rs:6–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5#[test]
6fn cases() {
7 let flags = TestRenamed::FLAGS
8 .iter()
9 .map(|flag| (flag.name(), flag.value().bits()))
10 .collect::<Vec<_>>();
11
12 assert_eq!(
13 vec![
14 ("custom", 1),
15 ("custom", 1 << 1),
16 ("c", 1 << 2),
17 ("custom | e", 1 << 3),
18 ],
19 flags,
20 );
21
22 // Original names are not recognized
23 assert!(TestRenamed::from_name("A").is_none());
24
25 // Regular renames are recognized
26 assert_eq!(TestRenamed::C, TestRenamed::from_name("c").unwrap());
27
28 // The first duplicate name is recognized
29 assert_eq!(TestRenamed::A, TestRenamed::from_name("custom").unwrap());
30
31 // Exotic names are recognized
32 assert_eq!(
33 TestRenamed::D,
34 TestRenamed::from_name("custom | e").unwrap()
35 );
36
37 // The parser doesn't have defined behavior on exotic names, but we
38 // make sure it does _something_
39 assert!(from_str_truncate::<TestRenamed>("custom | e").is_err());
40}

Callers

nothing calls this directly

Calls 4

iterMethod · 0.80
nameMethod · 0.80
valueMethod · 0.80
bitsMethod · 0.45

Tested by

no test coverage detected