cmake_parser/doc/command/deprecated/
install_files.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", untagged)]
13pub enum InstallFiles<'t> {
14 Files(InstallFilesAll<'t>),
15 RegEx(InstallFilesRegEx<'t>),
16 Extension(InstallFilesExtension<'t>),
17}
18
19impl<'t> ToCommandScope for InstallFiles<'t> {
20 fn to_command_scope(&self) -> CommandScope {
21 CommandScope::Deprecated
22 }
23}
24
25#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
26#[cmake(pkg = "crate")]
27pub struct InstallFilesAll<'t> {
28 #[cmake(positional)]
29 pub dir: Token<'t>,
30 pub files: Vec<Token<'t>>,
31}
32
33#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
34#[cmake(pkg = "crate", positional, complete)]
35pub struct InstallFilesRegEx<'t> {
36 pub dir: Token<'t>,
37 pub regex: Token<'t>,
38}
39
40#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
41#[cmake(pkg = "crate", positional)]
42pub struct InstallFilesExtension<'t> {
43 pub dir: Token<'t>,
44 pub extension: Token<'t>,
45 pub files: Vec<Token<'t>>,
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51 use crate::doc::cmake_parse::tests::{token, tokens_vec};
52 use crate::*;
53 use pretty_assertions::assert_eq;
54
55 #[test]
56 fn install_files() {
57 let src = include_bytes!("../../../../../fixture/commands/deprecated/install_files");
58 let cmakelists = parse_cmakelists(src).unwrap();
59 let doc = Doc::from(cmakelists);
60 assert_eq!(
61 doc.commands(),
62 Ok(vec![
63 Command::InstallFiles(Box::new(InstallFiles::Files(InstallFilesAll {
64 dir: token(b"dir1"),
65 files: tokens_vec([b"file1", b"file2"]),
66 }))),
67 Command::InstallFiles(Box::new(InstallFiles::RegEx(InstallFilesRegEx {
68 dir: token(b"dir1"),
69 regex: token(b"regex1"),
70 }))),
71 Command::InstallFiles(Box::new(InstallFiles::Extension(InstallFilesExtension {
72 dir: token(b"dir1"),
73 extension: token(b"extension1"),
74 files: tokens_vec([b"file1", b"file2"]),
75 }))),
76 ])
77 )
78 }
79}