cmake_parser/doc/command/scripting/
option.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", positional)]
13pub struct Option<'t> {
14 pub variable: Token<'t>,
15 pub help_text: Token<'t>,
16 pub value: std::option::Option<Token<'t>>,
17}
18
19impl<'t> ToCommandScope for Option<'t> {
20 fn to_command_scope(&self) -> CommandScope {
21 CommandScope::Scripting
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28 use crate::doc::cmake_parse::tests::{quoted_token, token};
29 use crate::*;
30 use pretty_assertions::assert_eq;
31
32 #[test]
33 fn option() {
34 let src = include_bytes!("../../../../../fixture/commands/scripting/option");
35 let cmakelists = parse_cmakelists(src).unwrap();
36 let doc = Doc::from(cmakelists);
37 assert_eq!(
38 doc.to_commands_iter().collect::<Vec<_>>(),
39 vec![
40 Ok(Command::Option(Box::new(Option {
41 variable: token(b"var1"),
42 help_text: quoted_token(b"enter var1"),
43 value: None,
44 }))),
45 Ok(Command::Option(Box::new(Option {
46 variable: token(b"var1"),
47 help_text: quoted_token(b"enter var1"),
48 value: Some(token(b"value1")),
49 }))),
50 ]
51 )
52 }
53}