clean_dev_dirs/config/
filter.rs

1//! Filtering configuration for project selection.
2//!
3//! This module defines the filtering options and project type filters used to
4//! determine which projects should be scanned and cleaned.
5
6use clap::ValueEnum;
7
8/// Enumeration of supported project type filters.
9///
10/// This enum is used to restrict scanning and cleaning to specific types of
11/// development projects.
12#[derive(Clone, Copy, PartialEq, Debug, ValueEnum, Default)]
13pub enum ProjectFilter {
14    /// Include all supported project types (Rust, Node.js, Python, Go)
15    #[default]
16    All,
17
18    /// Include only Rust projects (Cargo.toml + target/)
19    Rust,
20
21    /// Include only Node.js projects (package.json + `node_modules`/)
22    Node,
23
24    /// Include only Python projects (Python config files + cache dirs)
25    Python,
26
27    /// Include only Go projects (go.mod + vendor/)
28    Go,
29}
30
31/// Configuration for project filtering criteria.
32///
33/// This struct contains the filtering options used to determine which projects
34/// should be considered for cleanup based on size and modification time.
35#[derive(Clone)]
36pub struct FilterOptions {
37    /// Minimum size threshold for build directories
38    pub keep_size: String,
39
40    /// Minimum age in days for projects to be considered
41    pub keep_days: u32,
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_project_filter_equality() {
50        assert_eq!(ProjectFilter::All, ProjectFilter::All);
51        assert_eq!(ProjectFilter::Rust, ProjectFilter::Rust);
52        assert_eq!(ProjectFilter::Node, ProjectFilter::Node);
53        assert_eq!(ProjectFilter::Python, ProjectFilter::Python);
54        assert_eq!(ProjectFilter::Go, ProjectFilter::Go);
55
56        assert_ne!(ProjectFilter::All, ProjectFilter::Rust);
57        assert_ne!(ProjectFilter::Rust, ProjectFilter::Node);
58        assert_ne!(ProjectFilter::Node, ProjectFilter::Python);
59        assert_ne!(ProjectFilter::Python, ProjectFilter::Go);
60    }
61
62    #[test]
63    fn test_project_filter_copy() {
64        let original = ProjectFilter::Rust;
65        let copied = original;
66
67        assert_eq!(original, copied);
68    }
69
70    #[test]
71    fn test_project_filter_default() {
72        let default_filter = ProjectFilter::default();
73        assert_eq!(default_filter, ProjectFilter::All);
74    }
75
76    #[test]
77    fn test_filter_options_creation() {
78        let filter_opts = FilterOptions {
79            keep_size: "100MB".to_string(),
80            keep_days: 30,
81        };
82
83        assert_eq!(filter_opts.keep_size, "100MB");
84        assert_eq!(filter_opts.keep_days, 30);
85    }
86
87    #[test]
88    fn test_filter_options_clone() {
89        let original = FilterOptions {
90            keep_size: "100MB".to_string(),
91            keep_days: 30,
92        };
93        let cloned = original.clone();
94
95        assert_eq!(original.keep_size, cloned.keep_size);
96        assert_eq!(original.keep_days, cloned.keep_days);
97    }
98}