browserslist/queries/
supports.rs

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
use super::{Distrib, QueryResult};
use crate::{data::caniuse::features::get_feature_stat, error::Error};

pub(super) fn supports(name: &str) -> QueryResult {
    if let Some(feature) = get_feature_stat(name) {
        let distribs = feature
            .iter()
            .map(|(name, version)| Distrib::new(name, *version))
            .collect();
        Ok(distribs)
    } else {
        Err(Error::UnknownBrowserFeature(name.to_string()))
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{
        opts::Opts,
        test::{run_compare, should_failed},
    };
    use test_case::test_case;

    #[test_case("supports objectrtc"; "case 1")]
    #[test_case("supports    rtcpeerconnection"; "case 2")]
    #[test_case("supports        arrow-functions"; "case 3")]
    fn valid(query: &str) {
        run_compare(query, &Opts::new());
    }

    #[test]
    fn invalid() {
        assert_eq!(
            should_failed("supports xxxyyyzzz", &Opts::new()),
            Error::UnknownBrowserFeature(String::from("xxxyyyzzz"))
        );
    }
}