rust_diff_analyzer/classifier/path_classifier.rs
1// SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
2// SPDX-License-Identifier: MIT
3
4use std::path::Path;
5
6/// Checks if path is in examples directory
7///
8/// # Arguments
9///
10/// * `path` - Path to check
11///
12/// # Returns
13///
14/// `true` if path is in examples/
15///
16/// # Examples
17///
18/// ```
19/// use std::path::Path;
20///
21/// use rust_diff_analyzer::classifier::path_classifier::is_example_path;
22///
23/// assert!(is_example_path(Path::new("examples/demo.rs")));
24/// assert!(!is_example_path(Path::new("src/lib.rs")));
25/// ```
26pub fn is_example_path(path: &Path) -> bool {
27 path.to_string_lossy().contains("examples/")
28}
29
30/// Checks if path is in benches directory
31///
32/// # Arguments
33///
34/// * `path` - Path to check
35///
36/// # Returns
37///
38/// `true` if path is in benches/
39///
40/// # Examples
41///
42/// ```
43/// use std::path::Path;
44///
45/// use rust_diff_analyzer::classifier::path_classifier::is_bench_path;
46///
47/// assert!(is_bench_path(Path::new("benches/bench.rs")));
48/// assert!(!is_bench_path(Path::new("src/lib.rs")));
49/// ```
50pub fn is_bench_path(path: &Path) -> bool {
51 path.to_string_lossy().contains("benches/")
52}
53
54/// Checks if path is in tests directory
55///
56/// # Arguments
57///
58/// * `path` - Path to check
59///
60/// # Returns
61///
62/// `true` if path is in tests/
63///
64/// # Examples
65///
66/// ```
67/// use std::path::Path;
68///
69/// use rust_diff_analyzer::classifier::path_classifier::is_test_path;
70///
71/// assert!(is_test_path(Path::new("tests/integration.rs")));
72/// assert!(!is_test_path(Path::new("src/lib.rs")));
73/// ```
74pub fn is_test_path(path: &Path) -> bool {
75 path.to_string_lossy().contains("tests/")
76}
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81
82 #[test]
83 fn test_example_paths() {
84 assert!(is_example_path(Path::new("examples/main.rs")));
85 assert!(is_example_path(Path::new("crate/examples/demo.rs")));
86 assert!(!is_example_path(Path::new("src/examples.rs")));
87 }
88
89 #[test]
90 fn test_bench_paths() {
91 assert!(is_bench_path(Path::new("benches/perf.rs")));
92 assert!(!is_bench_path(Path::new("src/benches.rs")));
93 }
94
95 #[test]
96 fn test_test_paths() {
97 assert!(is_test_path(Path::new("tests/integration.rs")));
98 assert!(!is_test_path(Path::new("src/tests.rs")));
99 }
100}