cmake_parser/doc/command/scripting/
else.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    command::common::Condition,
5    doc::command_scope::{CommandScope, ToCommandScope},
6};
7
8/// Starts the else portion of an if block.
9///
10/// Reference: <https://cmake.org/cmake/help/v3.26/command/else.html>
11#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate", positional)]
13pub struct Else<'t> {
14    pub condition: Option<Condition<'t>>,
15}
16
17impl<'t> ToCommandScope for Else<'t> {
18    fn to_command_scope(&self) -> CommandScope {
19        CommandScope::Scripting
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26    use crate::doc::cmake_parse::tests::tokens_vec;
27    use crate::*;
28    use pretty_assertions::assert_eq;
29
30    #[test]
31    fn r#else() {
32        let src = include_bytes!("../../../../../fixture/commands/scripting/else");
33        let cmakelists = parse_cmakelists(src).unwrap();
34        let doc = Doc::from(cmakelists);
35        assert_eq!(
36            doc.commands(),
37            Ok(vec![
38                Command::Else(Box::new(Else { condition: None })),
39                Command::Else(Box::new(Else {
40                    condition: Some(Condition {
41                        conditions: tokens_vec([b"VAR1"]),
42                    })
43                })),
44            ])
45        )
46    }
47}