cmake_parser/doc/command/scripting/
get_property.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 GetProperty<'t> {
14 pub variable: Token<'t>,
15 #[cmake(in_range)]
16 pub scope: Scope<'t>,
17 #[cmake(transparent)]
18 pub property: Token<'t>,
19 pub options: Option<Options>,
20}
21
22impl<'t> ToCommandScope for GetProperty<'t> {
23 fn to_command_scope(&self) -> CommandScope {
24 CommandScope::Scripting
25 }
26}
27
28#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
29#[cmake(pkg = "crate", transparent, list)]
30pub enum Scope<'t> {
31 Global,
32 #[cmake(positional)]
33 Directory(Option<Token<'t>>),
34 Target(Token<'t>),
35 Source(Source<'t>),
36 Install(Token<'t>),
37 Test(Token<'t>),
38 Cache(Token<'t>),
39 Variable,
40}
41
42#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
43#[cmake(pkg = "crate")]
44pub enum Options {
45 Set,
46 Defined,
47 BriefDocs,
48 FullDocs,
49}
50
51#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
52#[cmake(pkg = "crate", positional)]
53pub struct Source<'t> {
54 pub source: Token<'t>,
55 pub scope: Option<DirectoryScope<'t>>,
56}
57
58#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
59#[cmake(pkg = "crate", transparent, list)]
60pub enum DirectoryScope<'t> {
61 Directory(Token<'t>),
62 TargetDirectory(Token<'t>),
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68 use crate::doc::cmake_parse::tests::token;
69 use crate::*;
70 use pretty_assertions::assert_eq;
71
72 #[test]
73 fn get_property() {
74 let src = include_bytes!("../../../../../fixture/commands/scripting/get_property");
75 let cmakelists = parse_cmakelists(src).unwrap();
76 let doc = Doc::from(cmakelists);
77 assert_eq!(
78 doc.to_commands_iter().collect::<Vec<_>>(),
79 vec![
80 Ok(Command::GetProperty(Box::new(GetProperty {
81 variable: token(b"variable1"),
82 scope: Scope::Global,
83 property: token(b"property1"),
84 options: None,
85 }))),
86 Ok(Command::GetProperty(Box::new(GetProperty {
87 variable: token(b"variable1"),
88 scope: Scope::Directory(Some(token(b"directory1"))),
89 property: token(b"property1"),
90 options: Some(Options::Set),
91 }))),
92 Ok(Command::GetProperty(Box::new(GetProperty {
93 variable: token(b"variable1"),
94 scope: Scope::Directory(None),
95 property: token(b"property1"),
96 options: Some(Options::Set),
97 }))),
98 Ok(Command::GetProperty(Box::new(GetProperty {
99 variable: token(b"variable1"),
100 scope: Scope::Target(token(b"target1")),
101 property: token(b"property1"),
102 options: Some(Options::Defined),
103 }))),
104 Ok(Command::GetProperty(Box::new(GetProperty {
105 variable: token(b"variable1"),
106 scope: Scope::Source(Source {
107 source: token(b"source1"),
108 scope: None
109 }),
110 property: token(b"property1"),
111 options: Some(Options::BriefDocs),
112 }))),
113 Ok(Command::GetProperty(Box::new(GetProperty {
114 variable: token(b"variable1"),
115 scope: Scope::Source(Source {
116 source: token(b"source1"),
117 scope: Some(DirectoryScope::Directory(token(b"directory1"))),
118 }),
119 property: token(b"property1"),
120 options: Some(Options::FullDocs),
121 }))),
122 Ok(Command::GetProperty(Box::new(GetProperty {
123 variable: token(b"variable1"),
124 scope: Scope::Source(Source {
125 source: token(b"source1"),
126 scope: Some(DirectoryScope::TargetDirectory(token(b"target_directory1"))),
127 }),
128 property: token(b"property1"),
129 options: None,
130 }))),
131 Ok(Command::GetProperty(Box::new(GetProperty {
132 variable: token(b"variable1"),
133 scope: Scope::Install(token(b"file1")),
134 property: token(b"property1"),
135 options: Some(Options::Set),
136 }))),
137 Ok(Command::GetProperty(Box::new(GetProperty {
138 variable: token(b"variable1"),
139 scope: Scope::Test(token(b"test1")),
140 property: token(b"property1"),
141 options: Some(Options::Defined),
142 }))),
143 Ok(Command::GetProperty(Box::new(GetProperty {
144 variable: token(b"variable1"),
145 scope: Scope::Cache(token(b"entry1")),
146 property: token(b"property1"),
147 options: Some(Options::BriefDocs),
148 }))),
149 Ok(Command::GetProperty(Box::new(GetProperty {
150 variable: token(b"variable1"),
151 scope: Scope::Variable,
152 property: token(b"property1"),
153 options: Some(Options::FullDocs),
154 }))),
155 ]
156 )
157 }
158}