use cmake_parser_derive::CMake;
use crate::{
command::common::Condition,
doc::command_scope::{CommandScope, ToCommandScope},
};
#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cmake(pkg = "crate", positional)]
pub struct Else<'t> {
pub condition: Option<Condition<'t>>,
}
impl<'t> ToCommandScope for Else<'t> {
fn to_command_scope(&self) -> CommandScope {
CommandScope::Scripting
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::doc::cmake_parse::tests::tokens_vec;
use crate::*;
use pretty_assertions::assert_eq;
#[test]
fn r#else() {
let src = include_bytes!("../../../../../fixture/commands/scripting/else");
let cmakelists = parse_cmakelists(src).unwrap();
let doc = Doc::from(cmakelists);
assert_eq!(
doc.commands(),
Ok(vec![
Command::Else(Box::new(Else { condition: None })),
Command::Else(Box::new(Else {
condition: Some(Condition {
conditions: tokens_vec([b"VAR1"]),
})
})),
])
)
}
}