cmake_parser/doc/command/scripting/
configure_file.rs1use cmake_parser_derive::CMake;
2
3use crate::{
4 command::common::{NewlineStyle, Permissions},
5 doc::command_scope::{CommandScope, ToCommandScope},
6 Token,
7};
8
9#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
13#[cmake(pkg = "crate")]
14pub struct ConfigureFile<'t> {
15 #[cmake(positional)]
16 pub input: Token<'t>,
17 #[cmake(positional)]
18 pub output: Token<'t>,
19 pub permissions: Option<Permissions<'t>>,
20 #[cmake(rename = "COPYONLY")]
21 pub copy_only: bool,
22 pub escape_quotes: bool,
23 #[cmake(rename = "@ONLY")]
24 pub only: bool,
25 pub newline_style: Option<NewlineStyle>,
26}
27
28impl<'t> ToCommandScope for ConfigureFile<'t> {
29 fn to_command_scope(&self) -> CommandScope {
30 CommandScope::Scripting
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37 use crate::doc::cmake_parse::tests::{token, tokens_vec};
38 use crate::*;
39 use pretty_assertions::assert_eq;
40
41 #[test]
42 fn configure_file() {
43 let src = include_bytes!("../../../../../fixture/commands/scripting/configure_file");
44 let cmakelists = parse_cmakelists(src).unwrap();
45 let doc = Doc::from(cmakelists);
46 assert_eq!(
47 doc.commands(),
48 Ok(vec![
49 Command::ConfigureFile(Box::new(ConfigureFile {
50 input: token(b"input1"),
51 output: token(b"output1"),
52 permissions: None,
53 copy_only: false,
54 escape_quotes: false,
55 only: false,
56 newline_style: None,
57 })),
58 Command::ConfigureFile(Box::new(ConfigureFile {
59 input: token(b"input1"),
60 output: token(b"output1"),
61 permissions: Some(Permissions::NoSource),
62 copy_only: false,
63 escape_quotes: false,
64 only: false,
65 newline_style: None,
66 })),
67 Command::ConfigureFile(Box::new(ConfigureFile {
68 input: token(b"input1"),
69 output: token(b"output1"),
70 permissions: Some(Permissions::UseSource),
71 copy_only: false,
72 escape_quotes: false,
73 only: false,
74 newline_style: None,
75 })),
76 Command::ConfigureFile(Box::new(ConfigureFile {
77 input: token(b"input1"),
78 output: token(b"output1"),
79 permissions: Some(Permissions::File(tokens_vec([b"file1", b"file2"]))),
80 copy_only: false,
81 escape_quotes: false,
82 only: false,
83 newline_style: None,
84 })),
85 Command::ConfigureFile(Box::new(ConfigureFile {
86 input: token(b"input1"),
87 output: token(b"output1"),
88 permissions: Some(Permissions::File(tokens_vec([b"file1", b"file2"]))),
89 copy_only: true,
90 escape_quotes: true,
91 only: true,
92 newline_style: Some(NewlineStyle::Unix),
93 })),
94 Command::ConfigureFile(Box::new(ConfigureFile {
95 input: token(b"input1"),
96 output: token(b"output1"),
97 permissions: None,
98 copy_only: false,
99 escape_quotes: false,
100 only: false,
101 newline_style: Some(NewlineStyle::Dos),
102 })),
103 Command::ConfigureFile(Box::new(ConfigureFile {
104 input: token(b"input1"),
105 output: token(b"output1"),
106 permissions: None,
107 copy_only: false,
108 escape_quotes: false,
109 only: false,
110 newline_style: Some(NewlineStyle::Win32),
111 })),
112 Command::ConfigureFile(Box::new(ConfigureFile {
113 input: token(b"input1"),
114 output: token(b"output1"),
115 permissions: None,
116 copy_only: false,
117 escape_quotes: false,
118 only: false,
119 newline_style: Some(NewlineStyle::Lf),
120 })),
121 Command::ConfigureFile(Box::new(ConfigureFile {
122 input: token(b"input1"),
123 output: token(b"output1"),
124 permissions: None,
125 copy_only: false,
126 escape_quotes: false,
127 only: false,
128 newline_style: Some(NewlineStyle::CrLf),
129 })),
130 ])
131 )
132 }
133}