fn exprs()

in watchman/rust/watchman_client/src/expr.rs [293:412]


    fn exprs() {
        assert_eq!(val(Expr::True), "true".into());
        assert_eq!(val(Expr::False), "false".into());
        assert_eq!(val(Expr::Empty), "empty".into());
        assert_eq!(val(Expr::Exists), "exists".into());
        assert_eq!(
            val(Expr::Not(Box::new(Expr::False))),
            vec!["not".into(), "false".into()].into()
        );
        assert_eq!(
            val(Expr::All(vec![Expr::True, Expr::False])),
            vec!["allof".into(), "true".into(), "false".into()].into()
        );
        assert_eq!(
            val(Expr::Any(vec![Expr::True, Expr::False])),
            vec!["anyof".into(), "true".into(), "false".into()].into()
        );

        assert_eq!(
            val(Expr::DirName(DirNameTerm {
                path: "foo".into(),
                depth: None,
            })),
            vec!["dirname".into(), Value::ByteString("foo".into())].into()
        );
        assert_eq!(
            val(Expr::DirName(DirNameTerm {
                path: "foo".into(),
                depth: Some(RelOp::GreaterOrEqual(1)),
            })),
            vec![
                "dirname".into(),
                Value::ByteString("foo".into()),
                vec!["depth".into(), "ge".into(), 1.into()].into()
            ]
            .into()
        );

        assert_eq!(
            val(Expr::Match(MatchTerm {
                glob: "*.txt".into(),
                ..Default::default()
            })),
            vec![
                "match".into(),
                "*.txt".into(),
                "basename".into(),
                hashmap! {
                    "includedotfiles".to_string() => Value::Bool(false),
                    "noescape".to_string() => Value::Bool(false),
                }
                .into()
            ]
            .into()
        );

        assert_eq!(
            val(Expr::Match(MatchTerm {
                glob: "*.txt".into(),
                wholename: true,
                include_dot_files: true,
                ..Default::default()
            })),
            vec![
                "match".into(),
                "*.txt".into(),
                "wholename".into(),
                hashmap! {
                    "includedotfiles".to_string() => Value::Bool(true),
                    "noescape".to_string() => Value::Bool(false),
                }
                .into()
            ]
            .into()
        );

        assert_eq!(
            val(Expr::Name(NameTerm {
                paths: vec!["foo".into()],
                wholename: true,
            })),
            vec![
                "name".into(),
                vec![Value::ByteString("foo".into())].into(),
                "wholename".into()
            ]
            .into()
        );

        assert_eq!(
            val(Expr::Pcre(PcreTerm {
                pattern: "foo$".into(),
                wholename: true,
            })),
            vec!["pcre".into(), "foo$".into(), "wholename".into()].into()
        );

        assert_eq!(
            val(Expr::FileType(FileType::Regular)),
            vec!["type".into(), "f".into()].into()
        );

        assert_eq!(
            val(Expr::Suffix(vec!["php".into(), "js".into()])),
            vec![
                "suffix".into(),
                vec![
                    Value::ByteString("php".into()),
                    Value::ByteString("js".into())
                ]
                .into()
            ]
            .into()
        );

        assert_eq!(
            val(Expr::Since(SinceTerm::ObservedClock(ClockSpec::null()))),
            vec!["since".into(), "c:0:0".into(), "oclock".into()].into()
        );
    }