opql/types/
pql_street.rs

1use super::*;
2
3#[derive(
4    Debug, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, Default, Display,
5)]
6pub enum PQLStreet {
7    #[default]
8    Flop = 1,
9    Turn,
10    River,
11}
12
13impl PQLStreet {
14    pub fn board_card_count(self) -> PQLCardCount {
15        prelude::Street::board_card_count(self.into())
16    }
17}
18
19impl From<PQLStreet> for prelude::Street {
20    fn from(v: PQLStreet) -> Self {
21        match v {
22            PQLStreet::Flop => Self::Flop,
23            PQLStreet::Turn => Self::Turn,
24            PQLStreet::River => Self::River,
25        }
26    }
27}
28
29impl FromStr for PQLStreet {
30    type Err = ParseError;
31
32    fn from_str(s: &str) -> Result<Self, Self::Err> {
33        match s.to_ascii_lowercase().trim() {
34            "flop" => Ok(Self::Flop),
35            "turn" => Ok(Self::Turn),
36            "river" => Ok(Self::River),
37
38            _ => Err(ParseError::InvalidStreet(s.into())),
39        }
40    }
41}
42
43#[cfg(test)]
44#[cfg_attr(coverage_nightly, coverage(off))]
45pub mod tests {
46    use super::*;
47    use crate::*;
48
49    impl quickcheck::Arbitrary for PQLStreet {
50        fn arbitrary(g: &mut quickcheck::Gen) -> Self {
51            #[allow(unused)]
52            const fn completeness_check(e: PQLStreet) {
53                match e {
54                    PQLStreet::Flop | PQLStreet::Turn | PQLStreet::River => (),
55                }
56            }
57
58            *g.choose(&[Self::Flop, Self::Turn, Self::River]).unwrap()
59        }
60    }
61
62    #[test]
63    fn test_from_str() {
64        assert_eq!(Ok(PQLStreet::Flop), "Flop".parse());
65        assert_eq!(Ok(PQLStreet::Turn), "tUrn".parse());
66        assert_eq!(Ok(PQLStreet::River), "riVer".parse());
67
68        assert_eq!(Ok(PQLStreet::Flop), " flop ".parse(), "should trim");
69
70        assert!("invalid".parse::<PQLStreet>().is_err());
71    }
72}