cmake_parser/doc/command/deprecated/
load_command.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    doc::command_scope::{CommandScope, ToCommandScope},
5    Token,
6};
7
8/// Load a command into a running CMake.
9///
10/// Reference: <https://cmake.org/cmake/help/v3.26/command/load_command.html>
11#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate", positional)]
13pub struct LoadCommand<'t> {
14    pub command_name: Token<'t>,
15    pub locations: Vec<Token<'t>>,
16}
17
18impl<'t> ToCommandScope for LoadCommand<'t> {
19    fn to_command_scope(&self) -> CommandScope {
20        CommandScope::Deprecated
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use crate::doc::cmake_parse::tests::{token, tokens_vec};
28    use crate::*;
29    use pretty_assertions::assert_eq;
30
31    #[test]
32    fn load_command() {
33        let src = include_bytes!("../../../../../fixture/commands/deprecated/load_command");
34        let cmakelists = parse_cmakelists(src).unwrap();
35        let doc = Doc::from(cmakelists);
36        assert_eq!(
37            doc.commands(),
38            Ok(vec![Command::LoadCommand(Box::new(LoadCommand {
39                command_name: token(b"command_name1"),
40                locations: tokens_vec([b"loc1", b"loc2"]),
41            })),])
42        )
43    }
44}