1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Matcher which will simply match all paths
//!
//! should be used only in specific strategies

use std::str::FromStr;

use super::MatchMaker;
use crate::{error, path::Path};

/// AllMatch to match array elements
#[derive(Debug, Clone, PartialEq)]
pub struct All;

impl Default for All {
    fn default() -> Self {
        All
    }
}

impl FromStr for All {
    type Err = error::Matcher;
    fn from_str(_: &str) -> Result<Self, Self::Err> {
        Ok(Self)
    }
}

impl MatchMaker for All {
    fn match_path(&self, _: &Path) -> bool {
        true
    }
}

#[cfg(test)]
mod tests {
    use super::{All, MatchMaker};
    use crate::path::Path;
    use std::{convert::TryFrom, str::FromStr};

    #[test]
    fn match_path() {
        let all = All::default();

        assert!(all.match_path(&Path::try_from(r#""#).unwrap()));
        assert!(all.match_path(&Path::try_from(r#"{"Any"}"#).unwrap()));
        assert!(all.match_path(&Path::try_from(r#"{"Any"}[0]{"Any"}"#).unwrap()));
    }

    #[test]
    fn all_parse() {
        assert!(All::from_str("").is_ok());
        assert!(All::from_str("*").is_ok());
        assert!(All::from_str("all").is_ok());
        assert!(All::from_str(".*").is_ok());
        assert!(All::from_str("any string").is_ok());
    }
}