manabrew_engine/zone/
zone_type.rs1pub use forge_foundation::ZoneType;
8
9pub fn is_hidden(zone: ZoneType) -> bool {
12 zone.is_hidden()
13}
14
15pub fn is_known(zone: ZoneType) -> bool {
18 zone.is_known()
19}
20
21pub fn smart_value_of(value: &str) -> Option<ZoneType> {
24 ZoneType::from_str_compat(value)
25}
26
27pub fn list_value_of(values: &str) -> Vec<ZoneType> {
31 if values.trim().eq_ignore_ascii_case("All") {
32 return vec![
33 ZoneType::Battlefield,
34 ZoneType::Hand,
35 ZoneType::Graveyard,
36 ZoneType::Exile,
37 ZoneType::Stack,
38 ZoneType::Library,
39 ZoneType::Command,
40 ];
41 }
42 let mut result = Vec::new();
43 for s in values.split([',', ' ']) {
44 let s = s.trim();
45 if s.is_empty() {
46 continue;
47 }
48 if let Some(zt) = smart_value_of(s) {
49 result.push(zt);
50 }
51 }
52 result
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn smart_value_of_test() {
61 assert_eq!(smart_value_of("Battlefield"), Some(ZoneType::Battlefield));
62 assert_eq!(smart_value_of("Hand"), Some(ZoneType::Hand));
63 assert_eq!(smart_value_of("All"), None);
64 }
65
66 #[test]
67 fn list_value_of_test() {
68 let result = list_value_of("Hand,Graveyard");
69 assert_eq!(result, vec![ZoneType::Hand, ZoneType::Graveyard]);
70 }
71
72 #[test]
73 fn list_value_of_all() {
74 let result = list_value_of("All");
75 assert_eq!(result.len(), 7);
76 assert!(result.contains(&ZoneType::Battlefield));
77 }
78}