cmake_parser/doc/command/scripting/
include.rs1use cmake_parser_derive::CMake;
2
3use crate::{
4 doc::command_scope::{CommandScope, ToCommandScope},
5 Token,
6};
7
8#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate")]
13pub struct Include<'t> {
14 #[cmake(positional)]
15 pub file: Token<'t>,
16 pub optional: bool,
17 pub result_variable: Option<Token<'t>>,
18 pub no_policy_scope: bool,
19}
20
21impl<'t> ToCommandScope for Include<'t> {
22 fn to_command_scope(&self) -> CommandScope {
23 CommandScope::Scripting
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use crate::doc::cmake_parse::tests::token;
31 use crate::*;
32 use pretty_assertions::assert_eq;
33
34 #[test]
35 fn include() {
36 let src = include_bytes!("../../../../../fixture/commands/scripting/include");
37 let cmakelists = parse_cmakelists(src).unwrap();
38 let doc = Doc::from(cmakelists);
39 assert_eq!(
40 doc.to_commands_iter().collect::<Vec<_>>(),
41 vec![
42 Ok(Command::Include(Box::new(Include {
43 file: token(b"file1"),
44 optional: false,
45 result_variable: None,
46 no_policy_scope: false,
47 }))),
48 Ok(Command::Include(Box::new(Include {
49 file: token(b"file1"),
50 optional: false,
51 result_variable: Some(token(b"var1")),
52 no_policy_scope: false,
53 }))),
54 Ok(Command::Include(Box::new(Include {
55 file: token(b"file1"),
56 optional: true,
57 result_variable: Some(token(b"var1")),
58 no_policy_scope: true,
59 }))),
60 ]
61 )
62 }
63}