cmake_parser/doc/command/project/
include_regular_expression.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    doc::command_scope::{CommandScope, ToCommandScope},
5    Token,
6};
7
8/// Set the regular expression used for dependency checking.
9///
10/// Reference: <https://cmake.org/cmake/help/v3.26/command/include_regular_expression.html>
11#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate", positional)]
13pub struct IncludeRegularExpression<'t> {
14    pub regex_match: Token<'t>,
15    pub regex_complain: Option<Token<'t>>,
16}
17
18impl<'t> ToCommandScope for IncludeRegularExpression<'t> {
19    fn to_command_scope(&self) -> CommandScope {
20        CommandScope::Project
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use crate::doc::cmake_parse::tests::quoted_token;
28    use crate::*;
29    use pretty_assertions::assert_eq;
30
31    #[test]
32    fn include_regular_expression() {
33        let src =
34            include_bytes!("../../../../../fixture/commands/project/include_regular_expression");
35        let cmakelists = parse_cmakelists(src).unwrap();
36        let doc = Doc::from(cmakelists);
37        assert_eq!(
38            doc.commands(),
39            Ok(vec![
40                Command::IncludeRegularExpression(Box::new(IncludeRegularExpression {
41                    regex_match: quoted_token(b"^[^.]+$|[.]h$|[.]icc$|[.]hxx$|[.]hpp$"),
42                    regex_complain: None,
43                })),
44                Command::IncludeRegularExpression(Box::new(IncludeRegularExpression {
45                    regex_match: quoted_token(b"^[^.]+$|[.]h$|[.]icc$|[.]hxx$|[.]hpp$"),
46                    regex_complain: Some(quoted_token(b"^[^.]+$|[.]h$|[.]icc$|[.]hxx$|[.]hpp$")),
47                })),
48            ])
49        )
50    }
51}